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

相关推荐
小白学大数据几秒前
Selenium库详解:Python实现模拟登录与反爬限制的进阶指南
python·selenium·测试工具
Cacciatore->10 分钟前
笔记 大学物理B下册
笔记
weixin_502539851 小时前
rust学习笔记5-所有权机制
笔记·学习·rust
StickToForever5 小时前
第4章 信息系统架构(五)
经验分享·笔记·学习·职场和发展
敲敲敲-敲代码9 小时前
【SQL实验】触发器
数据库·笔记·sql
Moonnnn.10 小时前
51单片机学习——动态数码管显示
笔记·嵌入式硬件·学习·51单片机
看,未来12 小时前
Apipost 与 Postman 工具实践指南:WebSocket调试与动态参数测试
websocket·测试工具·postman
电棍23312 小时前
verilog笔记
笔记·fpga开发
让我安静会12 小时前
Obsidian·Copilot 插件配置(让AI根据Obsidian笔记内容进行对话)
人工智能·笔记·copilot
shimly12345612 小时前
tcpdump 用法示例
网络·测试工具·tcpdump