selenium.webdriver元素定位失败
错误提示:
Traceback (most recent call last):
File "E:/PythonData/Login/venv/logIn.py", line 18, in <module>
driver2.switch_to.frame(driver2.find_element_by_xpath("//iframe[@id='x-URS-iframe']"))#切换到用户名和密码输入框所在的frame元素
File "E:\PythonData\Login\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 394, in find_element_by_xpath
return self.find_element(by=By.XPATH, value=xpath)
File "E:\PythonData\Login\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 978, in find_element
'value': value})['value']
File "E:\PythonData\Login\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "E:\PythonData\Login\venv\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//iframe[@id='x-URS-iframe']"}
(Session info: chrome=74.0.3729.108)
(Driver info: chromedriver=74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729@{#29}),platform=Windows NT 10.0.17134 x86_64)
解决办法:
可能原因:
页面元素未加载完成:可设置等待时间:
wait=WebDriverWait(driver2,10,1)#显示等待:10秒内,每1秒扫描一次
可能原因:iframe id 值与实际值不一致
查看页面实际值发现:ID值为 固定字符串+ 随机数
id="x-URS-iframe1556246512819.8438"
可以使用 xpath的三种办法来解决:
driver.find_element_by_xpath
("//div[contains(@id, 'btn-attention')]")
driver.find_element_by_xpath
("//div[starts-with(@id, 'btn-attention')]")
driver.find_element_by_xpath
("//div[ends-with(@id, 'btn-attention')]")
contains(a, b) 如果a中含有字符串b,则返回true,否则返回false
starts-with(a, b) 如果a是以字符串b开头,返回true,否则返回false
ends-with(a, b) 如果a是以字符串b结尾,返回true,否则返回false
selenium.webdriver元素定位失败的更多相关文章
- Selenium Webdriver元素定位的八种常用方式
楼主原创,欢迎学习和交流,码字不容易,转载请注明出处,谢谢. 在使用selenium webdriver进行元素定位时,通常使用findElement或findElements方法结合By类返回的元素 ...
- Selenium Webdriver元素定位的八种常用方法
如果你只是想快速实现控件抓取,而不急于了解其原理,可直接看: http://blog.csdn.net/kaka1121/article/details/51878346 如果你想学习web端自动化, ...
- Selenium Webdriver元素定位的八种常用方式(转载)
转载自 https://www.cnblogs.com/qingchunjun/p/4208159.html 在使用selenium webdriver进行元素定位时,通常使用findElement或 ...
- 爬虫-【selenium—Webdriver元素定位的八种常用方式
在使用selenium webdriver进行元素定位时,通常使用findElement或findElements方法结合By类返回的元素句柄来定位元素.其中By类的常用定位方式共八种,现分别介绍如下 ...
- Selenium Webdriver元素定位的八种常用方式【转】
在使用selenium webdriver进行元素定位时,通常使用findElement或findElements方法结合By类返回的元素句柄来定位元素.其中By类的常用定位方式共八种,现分别介绍如下 ...
- python3 selenium webdriver 元素定位xpath定位骚操作
源文http://www.cnblogs.com/qingchunjun/p/4208159.html By.xpath() 这个方法是非常强大的元素查找方式,使用这种方法几乎可以定位到页面上的任意元 ...
- selenium webdriver——元素定位
元素定位: >>WebDriver提供了八种元素定位方法,在Python语言中,所对应的方法如下: >>id属性定位:有唯一性 find_element_by_id(" ...
- Selenium Webdriver元素定位的常用方式
单选框.复选框.文本框和密码框的元素标签都是input,此时单靠tagName无法准确地得到我们想要的元素,需要结合type属性才能过滤出我们要的元素.示例代码如下: public class Sea ...
- Selenium Webdriver元素定位
http://www.cnblogs.com/qingchunjun/p/4208159.html
随机推荐
- oracle单机数据库搭建巨详细文档
规划 环境:redhat6.9 安装包:p13390677_112040_Linux-x86-64_1of7.zip p13390677_112040_Linux-x86-64_2of7.zip 数据 ...
- Docker 使用杂记 - 最佳实践尝试 - 实战
目录 Docker 使用杂记 - 最佳实践尝试 - 实战 Docker简介 项目背景 内在原因 外在原因 基础镜像 需求 镜像维护者 工作文件夹 文件 ADD COPY 宗卷 命令 入口点 Docke ...
- C++ 按行读取文件并打印
#include<iostream> #include<fstream> #include<string> #include <vector> #inc ...
- mysql的那些事之架构
MySQL架构的那些事 此篇博客为原创,欢迎转载,转载时请注明出处,谢谢 最近深入学习了一下mysql的内容,想把自己的理解分享出来. mysql架构 逻辑架构 Connectors:连接器 Mana ...
- 微信小程序开发(二)认识开发工具
腾讯微信团队提供非常优秀的微信小程序开发工具,大大降低了开发者的入门门槛,为他们点赞!上一篇文章已经说明了,如何注册及下载开发工具,现在我们就来一起认识见识一下开发工具的庐山真面目. 首次打开这个开发 ...
- 【Weiss】【第03章】双链表例程
双链表因为多了个前向指针,需要考虑的特殊因素多了一倍 所以中间插入(这儿没写)和中间删除会比较复杂. 其它倒没什么特别的,代码如下. 测试代码 #include <iostream> #i ...
- SpringCloud学习系列<一>版本介绍
SpringCloud学习踩坑记<一> SpringCloud版本迭代实在太快,学习起来也是各种坑,博主用的是"当前"的最新版本,借鉴周立老大的Spring Cloud ...
- Mol Cell Proteomics. | Identification of salivary biomarkers for oral cancer detection with untargeted and targeted quantitative proteomics approaches (解读人:卜繁宇)
文献名:Identification of salivary biomarkers for oral cancer detection with untargeted and targeted qua ...
- 说两个我在工作中有价值的bug
看了虫师在公众号上写的一边文章,叫做<面试官问,说一个你在工作非常有价值的bug>.看完虫师举的列子后,我也开始想之前测试的bug,想到之后,觉得有必要记录一下. First,在测试新闻动 ...
- 十分钟一起学会Inception网络
作者 | 荔枝boy 编辑 | 安可 一.Inception网络简介 二.Inception网络模块 三.Inception网络降低参数计算量 四.Inception网络减缓梯度消失现象 五.Ince ...