相关文章推荐
卖萌的烤地瓜  ·  MySQL整库同步Kafka - ...·  10 月前    · 
卖萌的烤地瓜  ·  All Aboard, Part 3: ...·  10 月前    · 
卖萌的烤地瓜  ·  typescript - Vue | ...·  11 月前    · 
聪明的作业本  ·  Advanced query ...·  1小时前    · 
失望的鸡蛋面  ·  "Microsoft Outlook ...·  1小时前    · 
坚强的柿子  ·  mongodb 多表关联处理 : ...·  1小时前    · 
不爱学习的火腿肠  ·  java ...·  3 小时前    · 
旅行中的铁链  ·  错误信息:SSL ShakeHand ...·  3 小时前    · 
憨厚的金鱼  ·  Scanpy数据结构:AnnData - 何帅 ·  3 小时前    · 

selenium.common.exceptions.TimeoutException: Message: 问题解决

好几天没学基础知识了,开始写自动化的框架了,中间遇到的问题,解决之后都记录下~

写了一个find_elements文件,调试的时候一执行报错:

D:\my\python\python.exe D:/my/learning/kuangjia/ZTKXin/Utilpackage/find_elements.py
****** xpath id
Traceback (most recent call last):
File "D:/my/learning/kuangjia/ZTKXin/Utilpackage/find_elements.py", line 11, in find_element
element = WebDriverWait(driver,10).until(lambda x:x.find_element(locate_mathod,locate_value))
File "D:\my\python\lib\site-packages\selenium\webdriver\support\wait.py", line 80, in until
raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message:

Traceback (most recent call last):
File "D:/my/learning/kuangjia/ZTKXin/Utilpackage/find_elements.py", line 33, in <module>
input_box = find_element(driver,"xpath","id")
File "D:/my/learning/kuangjia/ZTKXin/Utilpackage/find_elements.py", line 16, in find_element
raise e
File "D:/my/learning/kuangjia/ZTKXin/Utilpackage/find_elements.py", line 11, in find_element
element = WebDriverWait(driver,10).until(lambda x:x.find_element(locate_mathod,locate_value))
File "D:\my\python\lib\site-packages\selenium\webdriver\support\wait.py", line 80, in until
raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message:
Process finished with exit code 1

从错误原因直观看是因为等待时间问题:

所以先把等待时间从3秒加长到5秒,试了下不行!

再加长到10秒,还是不行!

那就不是等待时间的问题了,想了半天能跟等待时间挂钩的,肯定是元素定位问题,所以问题可能出在定位元素找不到上了。

改了下locate_value的内容,再试,果然可以了!

事后分析想下呢,我之前写的需要定位的值只写了一个id,找不到,后来,改成一个元素的正常的定位值就可以找到了。

本人菜鸟一个,正在学习,如果你也需要进步、学习、执行力能贯彻下去,希望我们互相监督,进我的框架群,纯交流!

一三五八一五八零零九四!

解决 selenium 模块操作浏览器报错) selenium . common . exception s. Timeout Exception : Message : script timeout 成功 解决 selenium . common . exception s. Timeout Exception : Message : timeout : Timed out receiving message from renderer: 294.905 (Session info: headless chrome=102.0.5005.115) 在这个例子中,我们使用WebDriverWait类等待目标元素加载完成,并使用ActionChains类模拟鼠标移动和点击操作。可以使用location_once_scrolled_into_view属性将元素滚动到视野范围内,或者使用ActionChains类模拟鼠标操作。可以使用execute_script()方法将元素滚动到视野范围内,或者使用ActionChains类模拟鼠标操作。可以使用WebDriverWait类等待元素变为可交互状态,或者通过JavaScript来修改元素状态。 在写完抓取脚本运行时候,发现脚本总会报错: selenium . common . exception s.NoSuchElement Exception : Message : no such element: Unable to locate element: {"method":"xpath","selector":"//span[contains(text(), '123565677')]" 可能是你在find_element_by_xpath()的书写中,其内容出错了 lambda d: d.find_element_by_xpath('//input[@id="kw]') 原来是我少打了一个分号 异常: selenium . common . exception s.ElementNotSelectable Exception (msg=None, screen =None, stack trace =None) 依据: selenium . common . exception s.InvalidElementState Exception 当尝试选择一个未能选中的元素时,异常会抛出 #-*-coding:utf-8-*-fromappiumimportwebdriverfrom selenium .webdriver.support.uiimportWebDriverWaitfrom selenium .webdriver.supportimportexpected_conditionsasEcimporttimecapabilites={"platf... Trace back (most recent call last): File "C:/Users/Administ ra tor/Desktop/WenShuSpider_v1/DetailC ra wl/ChromeProxyDetail_4.py", line 86, in get_detail self.driver.get(url) File "C:\Python\Python37\lib\site-packages\ selenium \webdriver\remote\webdriver. https://www.xin3721.com/eschool/python.html一、显示等待(有条件等待)常见 问题 :定位明明是对的,为什么运行代码没找到定位。定位明明是对的,找到定位了,文本信息为什么取到是空的?分析原因:没有处理f ra me页面渲染速度比自动化测试的代码慢,页面还没渲染出来就定位了异步请求,后端还未返回给前端,自动化测试代码就去获取页面文本数据一些同学的 解决 解决 方案:加上ti... from selenium import webdriver from selenium .webdriver. common .by import By from selenium .webdriver.support import expected_conditions from selenium .webdriver.support.wait import WebDriverWait url = 'http://image.baidu.com/' driver = webdriver.Chrome()
 
推荐文章