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

相关推荐
无敌小茶28 分钟前
Linux学习笔记之动静态库
linux·笔记
DXM05211 小时前
牟乃夏《ArcGIS Engine地理信息系统开发教程》学习笔记3-地图基本操作与实战案例
开发语言·笔记·学习·arcgis·c#·ae·arcgis engine
Humbunklung3 小时前
PySide6 GUI 学习笔记——常用类及控件使用方法(常用类矩阵QRectF)
笔记·python·学习·pyqt
曼诺尔雷迪亚兹4 小时前
Wireshark快速入门--对启动的后端程序进行抓包
网络·测试工具·wireshark
AAAA劝导tx5 小时前
List--链表
数据结构·c++·笔记·链表·list
愚润求学5 小时前
【Linux】进程优先级和进程切换
linux·运维·服务器·c++·笔记
愚润求学6 小时前
【专题四】前缀和(3)
开发语言·c++·笔记·leetcode·刷题·c++11
椰萝Yerosius6 小时前
铭记之日(3)——4.28
笔记
软件测试小仙女7 小时前
AI测试工具Testim——告别自动化测试维护难题
自动化测试·软件测试·人工智能·测试工具·单元测试·集成测试·压力测试
北漂老男孩8 小时前
二进制、高位低位、位移操作与进制转换全解
笔记