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

相关推荐
三水不滴11 小时前
Redis 持久化机制
数据库·经验分享·redis·笔记·缓存·性能优化
不断进步的咕咕怪11 小时前
meme分析
笔记
中屹指纹浏览器12 小时前
进程级沙箱隔离与WebGL指纹抗识别:指纹浏览器核心技术难点与工程落地
经验分享·笔记
sayang_shao12 小时前
Rust多线程编程学习笔记
笔记·学习·rust
进阶的猪12 小时前
Qt学习笔记
笔记·学习
mango_mangojuice12 小时前
Linux学习笔记 1.19
linux·服务器·数据库·笔记·学习
BlackWolfSky13 小时前
鸿蒙中级课程笔记6—使用ArkWeb开发
笔记·华为·harmonyos
浅念-13 小时前
C语言——双向链表
c语言·数据结构·c++·笔记·学习·算法·链表
ruxshui14 小时前
个人笔记: 星环Inceptor/hive普通分区表与范围分区表核心技术总结
hive·hadoop·笔记
慾玄14 小时前
渗透笔记总结
笔记