一.场景:
代码:
#coding:utf-8from selenium import webdriverfrom selenium.webdriver.common.action_chains import ActionChainsfrom selenium.webdriver.support.select import Selectimport timedriver=webdriver.Chrome()#打开百度首页driver.get("https://www.baidu.com")#使用鼠标悬停定位设置set=driver.find_element("link text","设置")time.sleep(2)#执行鼠标操作定位到"设置"ActionChains(driver).move_to_element(set).perform()time.sleep(2)#点击"搜索设置"driver.find_element_by_link_text("搜索设置").click()time.sleep(2)#选择"每页显示20条"s=driver.find_element_by_id("nr")Select(s).select_by_value("50")time.sleep(2)#使用jquery定位"保存设置"按钮jq="$(‘.prefpanelgo‘).click()"driver.execute_script(jq)time.sleep(2)#切换到alertal=driver.switch_to_alert()#打印al文本信息print al.text#在alert弹出框中点击确认按钮al.accept() time.sleep(2)driver.quit()
时间: 2024-10-27 05:45:04