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

相关推荐
程序员Xu4 小时前
【LeetCode热题100道笔记】二叉树的右视图
笔记·算法·leetcode
程序员Xu5 小时前
【LeetCode热题100道笔记】二叉搜索树中第 K 小的元素
笔记·算法·leetcode
DKPT5 小时前
JVM中如何调优新生代和老生代?
java·jvm·笔记·学习·spring
zhangzeyuaaa6 小时前
Selenium 超时完全指南:pageLoadTimeout、implicitlyWait 和 scriptTimeout 的深度解析
selenium·测试工具
我真的是大笨蛋8 小时前
K8S-基础架构
笔记·云原生·容器·kubernetes
程序员Xu11 小时前
【LeetCode热题100道笔记】腐烂的橘子
笔记·算法·leetcode
IT199511 小时前
Wireshark笔记-DHCP两步交互流程与数据解析
网络·笔记·wireshark
ST.J11 小时前
SQL与数据库笔记
数据库·笔记·sql
肥肠可耐的西西公主11 小时前
后端(JDBC)学习笔记(CLASS 1):基础篇(一)
笔记·学习
泛联新安12 小时前
如何根据项目需求选择合适的软件测试工具?iUnit智能单元测试平台提供专业化解决方案
c++·测试工具·单元测试