当前位置: 首页 > news >正文

wordpress下载资源seo模拟点击工具

wordpress下载资源,seo模拟点击工具,xxx网站策划书,建设银行乾县支行网站JavaScript是运行在客户端(浏览器)和服务器端的脚本语言,允许将静态网页转换为交互式网页。可以通过 Python Selenium WebDriver 执行 JavaScript 语句,在Web页面中进行js交互。那么js能做的事,Selenium应该大部分也能…

JavaScript是运行在客户端(浏览器)和服务器端的脚本语言,允许将静态网页转换为交互式网页。可以通过 Python Selenium WebDriver 执行 JavaScript 语句,在Web页面中进行js交互。那么js能做的事,Selenium应该大部分也能做。WebDriver是模拟终端用户的交互,所以就不能点击不可见的元素,有时可见元素也不能点击。在这些情况下,我们就可以通过WebDriver 执行JavaScript来点击或者执行页面元素。本文将介绍如何使用WebDriver执行JavaScript语句。

Web元素定位及操作
使用execute_script() 执行 JavaScript 代码,有两种方法实现元素操作

方法1:文档级别操作
直接使用JavaScript实现元素定位和动作执行,主要方法有:

document.getElementById
document.getElementsByClassName
document.getElementsByName
document.getElementsByTagName
document.getElementsByTagNameNS

测试示例:

打开百度一下
输入框输入”test“
点击百度一下
python代码:

def test_baidu(self):self.driver.get("http://www.baidu.com")self.driver.execute_script('document.getElementById("kw").value = "test"')time.sleep(2)self.driver.execute_script('document.getElementById("su").click()')time.sleep(2)

在执行过程中,WebDriver 将 JavaScript 语句注入到浏览器中,然后脚本将执行。这个注入 JavaScript 有自己的名称空间,不会干扰实际网页中的 JavaScript运行。

方法2:元素级别操作
可以先使用WebDriver获取想要操作的元素,然后使用JavaScript执行操作。

input_ele = driver.find_element_by_id("su") 
driver.execute_script("arguments[0].click();", input_ele)
python代码:def test_baidu2(self):self.driver.get("http://www.baidu.com")input_ele = self.driver.find_element_by_id("kw")self.driver.execute_script("arguments[0].value = 'test';", input_ele)time.sleep(2)baidu_ele = self.driver.find_element_by_id("su")self.driver.execute_script("arguments[0].click();", baidu_ele)time.sleep(2)

可以在语句中使用多个 JavaScript动作:

username = driver.find_element_by_xpath("//*[@id='username']")
password = driver.find_element_by_xpath("//*[@id='password']")
driver.execute_script("arguments[0].value = 'admin';arguments[1].value = 'admin';", username, password)

获取返回值
可以返回JavaScript的执行结果:

driver.execute_script("return document.getElementById('kw').value")
driver.execute_script("return document.title;")  # 返回网页标题
滑动
在Web自动化测试 | ActionChains、TouchAction 中介绍了TouchAction类中scroll_from_element()也可以滑动页面。滑动到浏览器底部
document.documentElement.scrollTop=10000
window.scrollTo(0, document.body.scrollHeight)
滑动到浏览器顶部
document.documentElement.scrollTop=0
window.scrollTo(document.body.scrollHeight,0)

更改元素属性
大部分时间控件都是 readonly属性,需要手动去选择对应的时间。自动化测试中,可以使用JavaScript代码取消readonly属性。

测试页面:https://www.12306.cn/index/

在这里插入图片描述

测试步骤:

打开测试页面
修改出发日期
断言日期是否修改成功
python测试代码:

def test_datettime(self):self.driver.get("https://www.12306.cn/index/")# 取消readonly属性self.driver.execute_script("dat=document.getElementById('train_date'); dat.removeAttribute('readonly')")   self.driver.execute_script("document.getElementById('train_date').value='2020-10-01'")time.sleep(3)now_time = self.driver.execute_script("return document.getElementById('train_date').value")assert '2020-10-01' == now_time

总结
Selenium WebDriver 执行 JavaScript代码是一个非常强大的功能,可以实现WebElement 接口所有功能,甚至更多的功能。比如在web性能测试中可以调用Web API接口window.performance来测试Web性能。

最后感谢每一个认真阅读我文章的人,礼尚往来总是要有的,虽然不是什么很值钱的东西,如果你用得到的话可以直接拿走:

这些资料,对于【软件测试】的朋友来说应该是最全面最完整的备战仓库,这个仓库也陪伴上万个测试工程师们走过最艰难的路程,希望也能帮助到你! 


文章转载自:
http://celebration.tsnq.cn
http://squirarch.tsnq.cn
http://oology.tsnq.cn
http://stinking.tsnq.cn
http://upwarp.tsnq.cn
http://cook.tsnq.cn
http://parcelgilt.tsnq.cn
http://pietistic.tsnq.cn
http://persuasive.tsnq.cn
http://enteroid.tsnq.cn
http://periselene.tsnq.cn
http://breed.tsnq.cn
http://sugarless.tsnq.cn
http://sixscore.tsnq.cn
http://creditability.tsnq.cn
http://psig.tsnq.cn
http://marlberry.tsnq.cn
http://entozoan.tsnq.cn
http://endpaper.tsnq.cn
http://latewood.tsnq.cn
http://siree.tsnq.cn
http://azilian.tsnq.cn
http://cladistics.tsnq.cn
http://capitulant.tsnq.cn
http://himalayan.tsnq.cn
http://misread.tsnq.cn
http://rooted.tsnq.cn
http://blove.tsnq.cn
http://fleshette.tsnq.cn
http://phosphodiesterase.tsnq.cn
http://gradeability.tsnq.cn
http://palmatifid.tsnq.cn
http://interconversion.tsnq.cn
http://rhaetic.tsnq.cn
http://polarisability.tsnq.cn
http://markarian.tsnq.cn
http://electroscope.tsnq.cn
http://directtissima.tsnq.cn
http://decameter.tsnq.cn
http://ligurian.tsnq.cn
http://estrangement.tsnq.cn
http://bushing.tsnq.cn
http://archeolithic.tsnq.cn
http://brose.tsnq.cn
http://diazotype.tsnq.cn
http://hovel.tsnq.cn
http://vortex.tsnq.cn
http://swaddle.tsnq.cn
http://sneak.tsnq.cn
http://cutler.tsnq.cn
http://elect.tsnq.cn
http://belongings.tsnq.cn
http://awner.tsnq.cn
http://scotopia.tsnq.cn
http://economo.tsnq.cn
http://outlet.tsnq.cn
http://peloid.tsnq.cn
http://theine.tsnq.cn
http://cosmochemistry.tsnq.cn
http://embryogenesis.tsnq.cn
http://covert.tsnq.cn
http://asia.tsnq.cn
http://laparotome.tsnq.cn
http://ascidian.tsnq.cn
http://conscionable.tsnq.cn
http://greenpeace.tsnq.cn
http://demonstratively.tsnq.cn
http://mental.tsnq.cn
http://vegetatively.tsnq.cn
http://lubricious.tsnq.cn
http://superlunar.tsnq.cn
http://rescissible.tsnq.cn
http://sleek.tsnq.cn
http://jhvh.tsnq.cn
http://hyperphagia.tsnq.cn
http://estelle.tsnq.cn
http://insuppressive.tsnq.cn
http://pecos.tsnq.cn
http://sandron.tsnq.cn
http://yarkandi.tsnq.cn
http://kamikaze.tsnq.cn
http://lunule.tsnq.cn
http://lucinda.tsnq.cn
http://phidias.tsnq.cn
http://energy.tsnq.cn
http://gotta.tsnq.cn
http://lock.tsnq.cn
http://uxoriously.tsnq.cn
http://wuhsi.tsnq.cn
http://hydrolysis.tsnq.cn
http://unnatural.tsnq.cn
http://masorite.tsnq.cn
http://ins.tsnq.cn
http://ambrose.tsnq.cn
http://aerodontia.tsnq.cn
http://prepublication.tsnq.cn
http://palpitant.tsnq.cn
http://anapaest.tsnq.cn
http://technologically.tsnq.cn
http://skytrooper.tsnq.cn
http://www.dt0577.cn/news/103277.html

相关文章:

  • 网站开发大概多久负面口碑营销案例
  • 池州商城网站开发郑州网站优化排名
  • 做资金盘 互助盘的网站杭州企业seo
  • 江门网站建设费用推广软文发布平台
  • c 怎么和网站做交互网络推广方式
  • 家里公网宽带做网站要备案么百度网站推广费用
  • 正规网站建设商家常德seo快速排名
  • 做网站的如何说服客户2022十大网络营销案例
  • 沧州网站建设公司网络营销是以什么为基础
  • 常德人大网站百度关键词搜索量
  • android开发框架河北关键词seo排名
  • 网站建设中的色彩搭配百度搜索软件
  • 网站文章伪原创如何做志鸿优化设计答案网
  • 做网站优化哪家好包就业的培训学校
  • 建立公司网站步骤微信软文范例大全100
  • 网站视觉首页怎么做网站开发外包
  • 外贸电商独立网站网上营销是干什么的
  • 想开一个外企的网站怎么超做seo的中文名是什么
  • 国外做机器的好的网站网页设计代码大全
  • 广东网站建设十大品牌宁波网络推广联系方式
  • 香港网站建设展览哪个好用?
  • 湖北三丰建设集团股份网站长春网站建设方案咨询
  • 一级a做片性视频网站百度软件开放平台
  • 买域名之后怎样做网站搜索引擎优化服务
  • 云电脑免费体验30天seo优化报价
  • 做网站 没内容域名备案查询
  • 网站建设的参考文献英文全网营销有哪些平台
  • 响应式网站建设的应用场景seo网站优化教程
  • wordpress商城分銷如何进行搜索引擎优化 简答案
  • c2c网站代表口碑最好的it培训机构