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

相关推荐
码途漫谈6 小时前
Easy-Vibe开发篇阅读笔记(四)——前端开发之结合 Agent Skills 美化界面
人工智能·笔记·ai·开源·ai编程
糖炒栗子03268 小时前
【笔记】高分卫星影像 TIF 切片处理
笔记
Nice_Fold9 小时前
Kubernetes DaemonSet、StatefulSet与Service(自用笔记)
笔记·容器·kubernetes
西安同步高经理10 小时前
B码发生器破解变电站故障录波的时间困局、b码同步时钟、b码授时
测试工具
ZhiqianXia12 小时前
《The Design of Design》阅读笔记
前端·笔记·microsoft
祁白_12 小时前
nmap工具笔记整理
笔记·web安全·测试
大貔貅喝啤酒12 小时前
接口测试_Postman(详细版)
javascript·测试工具·node.js·自动化·postman
南境十里·墨染春水12 小时前
C++笔记 STL——set
开发语言·c++·笔记
d111111111d12 小时前
直流电机位置式 PID 控制 和 舵机的区别
笔记·stm32·单片机·嵌入式硬件·学习
LZYmarks13 小时前
小白买车笔记
笔记