Python 官方文档:入门教程 => 点击学习
WEBDriver有2个方法执行Java Script脚本。 (1)同步执行:execute_script (2)异步执行:execute_async_script from s
WEBDriver有2个方法执行Java Script脚本。
(1)同步执行:execute_script
(2)异步执行:execute_async_script
from selenium import webdriver
from time import sleep
class TestScriptss(object):
def setup(self):
self.driver = webdriver.Chrome()
self.driver.get(Http://www.baidu.com)
#执行js提示框,并点确定
def test_scripts(self):
self.driver.execute_script("alert('test')")
sleep(2)
self.driver.switch_to.alert.accept()
self.driver.quit()
#执行脚本获取当前页面标题
def test_scripts(self):
js = "return document.title"
title = self.driver.execute_script(js)
print(title)
sleep(2)
self.driver.quit()
#格式化文本框
def test_fORMat(self):
js = 'var q = document.getElementById("kw"); q.style.border="10px solid red"'
self.driver.execute_script(js)
sleep(5)
self.driver.quit()
#通过脚本实现页面滚动
def test_scroll(self):
self.driver.find_element_by_id('kw').send_keys('selenium test')
self.driver.find_element_by_id('su').click()
sleep(2)
#搜索结果页面滚动
js = 'window.scrollTo(0, document.body.scrollHeight)'
# 同步执行
self.driver.execute_script(js)
#异步执行
# self.driver.execute_async_script(js)
sleep(2)
self.driver.quit()
以上来自:极客时间课程:selenium自动化测试学习总结。
以上就是python自动化测试selenium执行js脚本实现示例的详细内容,更多关于selenium测试框架的资料请关注编程网其它相关文章!
--结束END--
本文标题: python自动化测试selenium执行js脚本实现示例
本文链接: https://www.lsjlt.com/news/157232.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0