【笔记】太久没有写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()

相关推荐
wdfk_prog3 分钟前
[Linux]学习笔记系列 -- [fs]super
linux·笔记·学习
日更嵌入式的打工仔38 分钟前
单片机基础知识:内狗外狗/软狗硬狗
笔记·单片机
KhalilRuan39 分钟前
数据结构与算法-笔记
笔记
可可南木1 小时前
3070文件格式--2--board文件格式详解 2
功能测试·测试工具·pcb工艺
KhalilRuan3 小时前
秋招笔记汇总
笔记
laplace01233 小时前
Part3 RAG文档切分
笔记·python·中间件·langchain·rag
被遗忘的旋律.3 小时前
Linux驱动开发笔记(二十三)—— regmap
linux·驱动开发·笔记
测试老哥3 小时前
2026最新软件测试面试热点问题(含答案+文档)
自动化测试·软件测试·python·测试工具·面试·职场和发展·测试用例
技术宅学长4 小时前
关于CLS与mean_pooling的一些笔记
人工智能·pytorch·笔记·pycharm
sww_10264 小时前
JVM基础学习
jvm·学习·测试工具