selenium basis (treatment warning box)

selenium basis (treatment warning box)

In the warning processing block webdriver generated JavaScript There are three types

  • alert
  • confirm
  • prompt

Transfer to alert box approach is: driver.switch_to.alert

Then use text, accept, dismiss, send_keys the like operating

  • text: return (get) alert text message / confirm / prompt in
  • accpet (): accept the existing alert box
  • dismiss (): the dissolution of the existing alert box
  • send_keys (keysToSend): to send a text alert box
from selenium import webdriver
import time
from webdriver.common.action_chains import ActionChains

driver=webdriver.Firefox()
driver.get("https://www.baidu.com")
driver.maximize_window()
a=driver.find_element_by_link_text("设置")
ActionChains(driver).move_to_element(a).perform()
driver.find_element_by_link_text("搜索设置").click()
driver.find_element_by_link_text("保存设置").click()
driver.switch_to.alert.accept () # accept the warning box, click the button in the warning box that is 

driver.quit ()

 

Guess you like

Origin www.cnblogs.com/jingdenghuakai/p/11695147.html