Python教程

Note4:selenium+python Alert的一些操作

本文主要是介绍Note4:selenium+python Alert的一些操作,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
from selenium.webdriver import ActionChains

# driver= webdriver.Firefox()
driver= webdriver.Chrome()
driver.get("https://www.baidu.com/")
driver.maximize_window()


driver.find_element_by_xpath("//*[@id=\"kw\"]").send_keys("selenium")
driver.find_element_by_xpath("//*[@id=\"kw\"]").submit()


time.sleep(2)
# above=driver.find_element_by_xpath("//span[@id=\"s-usersetting-top\"]")
above=driver.find_elements_by_xpath("//*[text()=\"设置\"]")[1]
ActionChains(driver).move_to_element(above).perform()

SearchSetting_Ele=driver.find_element_by_xpath("//*[text()=\"搜索设置\"][1]")
SearchSetting_Ele.click()

time.sleep(2)
# driver.find_elements_by_xpath("//*[text()='高级搜索']")[1].click()
driver.find_element_by_xpath("(//*[text()='高级搜索'])[2]").click()
driver.find_element_by_xpath("//*[@id=\"adv_keyword\"]").send_keys("包含全部关键词")
driver.find_element_by_xpath("//input[@class=\"c-input adv-q-input switch-input\" and @name=\"q2\"]").send_keys("包含完整关键词")
driver.find_element_by_xpath("//input[@class=\"c-input adv-q-input switch-input\" and @name=\"q3\"]").send_keys("包含任意关键词")
driver.find_element_by_xpath("//div[@class=\"c-select-selection\"]/i[1]").click()
driver.find_element_by_xpath("//p[@class=\"c-select-item\" and @data-for=\"gpc\"][4]").click()
driver.find_element_by_xpath("(//i[@class=\"c-icon c-select-arrow\"])[2]").click()
driver.find_element_by_xpath("//*[text()=\"所有格式\"]").click()
driver.find_element_by_xpath("//*[@id=\"q5_2\"]").click()
# driver.find_element_by_xpath("//*[@value=\"高级搜索\"]").click()
# time.sleep(2)
driver.find_element_by_xpath("//*[@class=\"item\" and @data-tabid=\"general\"]").click()
driver.find_element_by_xpath("//*[text()=\"保存设置\"]").click()


# ***********操作百度弹出的Alert
alert=driver.switch_to.alert
print(alert.text)
# alert.accept()
# alert.send_keys("a")
alert.dismiss()











这篇关于Note4:selenium+python Alert的一些操作的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!