from seleniumimport webdriver
from selenium.webdriver.support.selectimport Select
from selenium.webdriver.common.action_chainsimport ActionChains
import time
# 下拉框定位
driver = webdriver.Chrome()
driver.maximize_window()
url ="https://www.baidu.com/"
driver.get(url)
driver.implicitly_wait(10)
a = driver.find_element_by_link_text("设置")
ActionChains(driver).move_to_element(a).perform()
driver.find_element_by_link_text("搜索设置").click()
time.sleep(3)
# driver.find_element_by_id("nr").click()
# driver.find_element_by_xpath(".//*[@id='nr']/option[3]").click()
b = driver.find_element_by_id("nr")
Select(b).select_by_index(2)
b.click()
Select(b).select_by_value("50")
b.click()
Select(b).select_by_visible_text("每页显示20条")
b.click()
driver.find_element_by_link_text("保存设置").click()
#针对Alert弹窗处理
c = driver.switch_to.alert#切换到alert
d = c.text
print(d)
time.sleep(3)
c.accept()
driver.quit()
网友评论