Python+Selenium笔记(十五)调用JS
2020-02-02 17:12
676 查看
(一) 方法
方法 |
简单说明 |
execute_async_script(script, args)
|
异步执行JS代码 script:被执行的JS代码 args:js代码中的任意参数 |
execute_script(script, args) |
同步执行JS代码 script:被执行的JS代码 args:js代码中的任意参数 |
(二) 示例
from selenium.webdriver.common.action_chains import ActionChains from selenium import webdriver import time driver = webdriver.Chrome() driver.implicitly_wait(20) driver.maximize_window() driver.get('https://www.cnblogs.com/') #给元素加上红色边框,0.3秒后还原 def highlightElement(element): driver.execute_script("arguments[0].setAttribute('style',arguments[1]);",element, "border:2px solid red;") time.sleep(0.3) driver.execute_script("arguments[0].setAttribute('style',arguments[1]);", element, "") program_lan = driver.find_element_by_xpath('//li[@id="cate_item_2"]/a') program_py = driver.find_element_by_xpath('//li/a[@href="/cate/python/"]') highlightElement(program_lan) #鼠标先移动到“编程语言”上,然后点击Python ActionChains(driver).move_to_element(program_lan).click(program_py).perform() driver.quit()
转载于:https://www.cnblogs.com/simple-free/p/8528505.html
- 点赞
- 收藏
- 分享
- 文章举报
相关文章推荐
- python之selenium调用js(execute_script)
- selenium_webdriver(python)调用js脚本
- python selenium 滚动条/调用JavaScript/js
- python之selenium调用js(execute_script)
- 程序语言(python、php、Node.js)调用Redis
- 在python中调用js或者nodejs
- Eel——js 如何调用python的函数
- Selenium with Python 005 - 调用js操作页面元素
- Python3 调用 Node.js 解析 MathJax 公式
- 1.Selenium2 自动化测试实战-基于Python语言-设置窗口大小、调用JS调整滚动条、截取图片
- python 调用js中的方法
- Python 执行js的2种解决方案 调用spidermonkey和安装pythonspidermonkey
- Python执行js脚本,调用node.js
- python——Django项目开发:配置项目/static/路径,调用css、img、js等静态文件
- python webdriver调用JS操作日期控件
- Selenium--调用js,对话框处理 (python)
- Python的学习(十五)---- 调用windows下DLL详解
- Webdriver (python)中调用JS
- Python中Django中的JS异步调用疑难杂症
- openerp js调用Python类方法