python + selenium alter the pop object processing 01

alt.accept (): same as clicking the "OK" or "OK"

alt.dismiss (): same as clicking "Cancel" or "Cancel"

alt.send_keys (): send text, prompt box has submitted the demand for

alt.text (): Gets the contents of a text alert

alt.authenticate (username, password): verification, identity verification for the needs of alert

 

-------------------------------------------------------------------------------------------------------------------

Pop browser does not belong to html page elements, but to the windows of the control elements, all use


And multiple browsers manner, i.e. using the class switch housing shells way to get

 

<HTML>
<head>
<Script type = "text / JavaScript">
function show_alert () {
Alert ( 'the first row \ n second row');
}

function show_confirm () {
var Confirm Result = ( 'Delete! ');
IF (the Result) {
Alert ( "deleted successfully');!
the else {}
Alert ( 'do not delete');!
}
}

function show_prompt () {
var value = prompt (" enter your name: '' the default name ');
IF (value == null) {
Alert ( "you cancel the input!');
} the else IF (value == '') {
Alert ( 'name input is empty, please try again!');
show_prompt ();
} the else {
Alert ( 'Hello,' + value);
}
}
</ Script>
</ head>
<body>
<input id="alert_button" type="button" value="alert" onclick="show_alert()" >
<input id="confirm_button" type="button" value="confirm" onclick="show_confirm()" >
<input id="prompt_button" type="button" value="prompt" onclick="show_prompt()" >
</body>
</html>

 


Desktop create this html document: tanchuang.html


file:///C:/Users/del/Desktop/tanchuang.html

 

 

==============================================================

 

Import the webdriver Selenium from 
from the Alert selenium.webdriver.common.alert Import
from SLEEP Time Import

Driver = webdriver.Firefox () # Specify and open the browser
driver.get ( 'file: /// C: / Users / del / Desktop / tanchuang.html ')

driver.find_element_by_id (' alert_button '). the click () # click the trigger bomb box elements
SLEEP (5)

driver.switch_to.alert.accept ()
SLEEP (5)



driver.find_element_by_id (' alert_button ') .click ()
Alt = the Alert (Driver)
SLEEP (. 3)
alt.accept ()
SLEEP (. 5)



driver.close ()

====================== ==================================================

Import the webdriver Selenium from 
from the Alert selenium.webdriver.common.alert Import
from SLEEP Time Import


Driver = webdriver.Firefox () # Specify and open the browser
driver.get ( 'file: /// C: / Users / del / Desktop / tanchuang.html ')


driver.find_element_by_id (' confirm_button '). the click () # click the trigger bomb box elements

SLEEP (5)
driver.switch_to.alert.dismiss () # click the cancel button

SLEEP (8)
driver.switch_to. alert.accept () # click OK to

sleep (8)

driver.find_element_by_id ( 'confirm_button'). the click () # click the trigger bomb box elements


sleep (5)
driver.switch_to.alert.accept () # click the OK button
sleep (8)
driver.switch_to.alert.accept () # click OK
SLEEP (8)


driver.close ()

===============================================================================


Import the webdriver Selenium from 
from the Alert selenium.webdriver.common.alert Import
from SLEEP Time Import


Driver = webdriver.Firefox () # Specify and open the browser
driver.get ( 'file: /// C: / Users / del / Desktop / tanchuang.html ')


driver.find_element_by_id (' prompt_button '). the click () # click the trigger bomb box elements

SLEEP (5)
Print (driver.switch_to.alert.text) # print alter the text inside the text box

driver.switch_to .alert.send_keys ( 'Shen Wei Wei')


SLEEP (5)
driver.switch_to.alert.accept () # click OK

SLEEP (5)
driver.switch_to.alert.accept () # click OK

SLEEP (5)


driver.close ()


Guess you like

Origin www.cnblogs.com/xiaobaibailongma/p/12040914.html