错误提示:

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元素定位失败的更多相关文章

  1. Selenium Webdriver元素定位的八种常用方式

    楼主原创,欢迎学习和交流,码字不容易,转载请注明出处,谢谢. 在使用selenium webdriver进行元素定位时,通常使用findElement或findElements方法结合By类返回的元素 ...

  2. Selenium Webdriver元素定位的八种常用方法

    如果你只是想快速实现控件抓取,而不急于了解其原理,可直接看: http://blog.csdn.net/kaka1121/article/details/51878346 如果你想学习web端自动化, ...

  3. Selenium Webdriver元素定位的八种常用方式(转载)

    转载自 https://www.cnblogs.com/qingchunjun/p/4208159.html 在使用selenium webdriver进行元素定位时,通常使用findElement或 ...

  4. 爬虫-【selenium—Webdriver元素定位的八种常用方式

    在使用selenium webdriver进行元素定位时,通常使用findElement或findElements方法结合By类返回的元素句柄来定位元素.其中By类的常用定位方式共八种,现分别介绍如下 ...

  5. Selenium Webdriver元素定位的八种常用方式【转】

    在使用selenium webdriver进行元素定位时,通常使用findElement或findElements方法结合By类返回的元素句柄来定位元素.其中By类的常用定位方式共八种,现分别介绍如下 ...

  6. python3 selenium webdriver 元素定位xpath定位骚操作

    源文http://www.cnblogs.com/qingchunjun/p/4208159.html By.xpath() 这个方法是非常强大的元素查找方式,使用这种方法几乎可以定位到页面上的任意元 ...

  7. selenium webdriver——元素定位

    元素定位: >>WebDriver提供了八种元素定位方法,在Python语言中,所对应的方法如下: >>id属性定位:有唯一性 find_element_by_id(" ...

  8. Selenium Webdriver元素定位的常用方式

    单选框.复选框.文本框和密码框的元素标签都是input,此时单靠tagName无法准确地得到我们想要的元素,需要结合type属性才能过滤出我们要的元素.示例代码如下: public class Sea ...

  9. Selenium Webdriver元素定位

    http://www.cnblogs.com/qingchunjun/p/4208159.html

随机推荐

  1. Ajax上传数据和上传文件(三种方式)

    Ajax向后端发送数据可以有三种方式:原生Ajax方式,jQuery Ajax方式,iframe+form 方式(伪造Ajax方式) <!DOCTYPE html> <html la ...

  2. 今天对C语言不常用的小东西的了解

    今天又翻了C语言的书,看到const语句,一时间想不起来到底是干嘛的,看语句const   int   a=1;明白了这是一个支持常量指定类型的定义常量的关键字,作用几乎与#define一毛一样,但# ...

  3. python3.4.3 调用http接口 解析response xml后插入数据库

    工作中需要调用一个http的接口,等不及java组开发,就试着用python去调用.Python版本3.4.3 完整的流程包括:从sqlServer取待调用的合同列表 -> 循环调用http接口 ...

  4. Spring Boot 结合 Redis 序列化配置的一些问题

    前言 最近在学习Spring Boot结合Redis时看了一些网上的教程,发现这些教程要么比较老,要么不知道从哪抄得,运行起来有问题.这里分享一下我最新学到的写法 默认情况下,Spring 为我们提供 ...

  5. 关于使用 Laravel 服务容器的优势介绍

    如果说laravel框架的核心是什么,那么无疑是服务容器.理解服务容器的概念,对于我们使用laravel太重要了,应该说是否理解服务容器的概念是区分是否入门laravel的重要条件.因为整个框架正是在 ...

  6. [BUG]Uncaught TypeError: Illegal invocation at HTMLDivElement.

    <div id="clickMe" key="1">点我</div> clickMe.onclick = function (event ...

  7. Linux内核文档:如何写符合 kernel-doc 规范的注释

    简介 Linux内核使用 Sphinx 实现把 Documentation 目录下的 reStructuredText 文件转换为非常漂亮的文档.文档既可以通过 make htmldocs 转换成 H ...

  8. 可运行jar包的几种打包/部署方式(转)

    转自:https://www.cnblogs.com/yjmyzz/p/executable-jar.html java项目开发中,最终生成的jar,大概可分为二类,一类是一些通用的工具类(不包含ma ...

  9. EPX-Studio调用Dll模块

    procedure TForm1.BitBtn1Click(Sender: TObject); var REP : IExcelPanelXDisp; modulePath:string; begin ...

  10. spring动态添加bean

    不知道大家想过没有,我们使用mybatis的时候只要写接口和配置上一个sql语句就可以了,单从代码的角度来看,这是不合理的. 所以我们通常在service里面注入的mapper它其实是一个代理对象 ​ ...