Python3+Selenium3+webdriver学习笔记13(js操作应用:弹出框无效如何处理)

#!/usr/bin/env python
# -*- coding:utf-8 -*-
'''
Selenium3+webdriver学习笔记13(js操作应用:弹出框无效如何处理)
'''
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.select import Select
import time,os # about:addons 火狐浏览器安装组件,访问的地址 # <input id="kw" name="wd" class="s_ipt" value="" maxlength="255" autocomplete="off">
#id
keys="设置"
delay=3
url="https://www.baidu.com/"
driver=webdriver.Firefox() driver.get(url) mouse=driver.find_element_by_link_text(keys)
ActionChains(driver).move_to_element(mouse).perform()
time.sleep(delay) driver.find_element_by_link_text("搜索设置").click()
time.sleep(delay) # <select name="NR" id="nr">
# <option value="10" selected="">每页显示10条</option>
# <option value="20">每页显示20条</option>
# <option value="50">每页显示50条</option>
# </select> se=driver.find_element_by_id("nr")
Select(se).select_by_index(2) #一般方式
# <div id="gxszButton"><a href="#" class="prefpanelgo">保存设置</a><a href="#" class="prefpanelrestore">恢复默认</a></div>
driver.find_element("id","gxszButton").click()
driver.find_element("class name","prefpanelgo").click() #脚本方式
js='document.getElementsByClassName("prefpanelgo")[0].click();'
driver.execute_script(js) driver.quit()
上一篇:Jenkins持续集成体系 | 最完整的介绍及资料


下一篇:Windows 下针对python脚本做一个简单的进程保护