【笔记】太久没有写selenium了

以前qyqt和selenium用来开发一个自动化测试工具,现在回忆一下已经过了将近6年。

DeprecationWarning: find_element_by_* commands are deprecated. Please use find_element()

例如:find_element_by_xpath改为web.find_element(By.XPATH

from selenium.webdriver.common.by import By

find_element(By.ID,"id") 等价于 find_element_by_id -->根据id属性定位

find_element(By.XPATH,"//div[@name='csdn']") 等价于

find_element_by_xpath -->根据XPATH路径来定位

find_element(By.LINK_TEXT,"text") 等价于 findfind_element_by_link_text

-->根据超链接标签匹配(精准匹配,匹配a标签的全部文本内容。)

find_element(By.PARTIAL_LINK,"partialtext") 等价于 find_element_by_partial_link_text -->根据超链接标签匹配(非精准匹配,匹配a标签的部分文本内容。)

find_element(By.ID,"name") 等价于 find_element_by_name -->根据name属性定位

find_element(By.TAG_NAME,"input") 等价于 find_element_by_tag_name -->根据标签名定位,例如input标签

find_element(By.CLASS_NAME,"classname") 等价于 find_element_by_class_name -->根据类名属性定位find_element(By.CSS,"#id") 等价于 find_element_by_css_selector -->根据css选择器名字定位

Message: 'geckodriver' executable needs to be in PATH

复制代码
from selenium.webdriver.firefox.service import Service
s = Service("geckodriver.exe")
driver = webdriver.Firefox(service=s)

selenium.webdriver' has no attribute 'current_url'

用声明出来的driver来使用属性

保存图片

driver.find_element_by_xpath('//body/img[1]').screenshot("a.jpg")

screenshot_as_jpg()

相关推荐
_Kayo_3 小时前
node.js 学习笔记3 HTTP
笔记·学习
星星火柴9367 小时前
关于“双指针法“的总结
数据结构·c++·笔记·学习·算法
秃了也弱了。7 小时前
WireShark:非常好用的网络抓包工具
网络·测试工具·wireshark
敲上瘾9 小时前
Linux系统cgroups资源精细化控制基础
linux·测试工具·docker·压力测试·cgroups
Cx330❀9 小时前
【数据结构初阶】--排序(五):计数排序,排序算法复杂度对比和稳定性分析
c语言·数据结构·经验分享·笔记·算法·排序算法
小幽余生不加糖10 小时前
电路方案分析(二十二)适用于音频应用的25-50W反激电源方案
人工智能·笔记·学习·音视频
..过云雨10 小时前
01.【数据结构-C语言】数据结构概念&算法效率(时间复杂度和空间复杂度)
c语言·数据结构·笔记·学习
岑梓铭11 小时前
考研408《计算机组成原理》复习笔记,第五章(3)——CPU的【数据通路】
笔记·考研·408·计算机组成原理·计组
gc_229914 小时前
使用HtmlAgilityPack+PuppeteerSharp+iText7抓取Selenium帮助文档
selenium·itext7·htmlagilitypack·puppeteersharp
天才测试猿15 小时前
常见的Jmeter压测问题
自动化测试·软件测试·python·测试工具·jmeter·职场和发展·压力测试