python - 如何使用 python 修复“selenium.common.exceptions.WebDriverException: Message: Failed to write request to stream”
问题描述
环境:
蟒蛇 3.9.7
硒==3.141.0
问题:
我正在尝试使用 selenium 在网站上获取元素。
button_LogIn = WebDriverWait(p_driver, 10).until(EC.presence_of_element_located(
(By.XPATH, ("//a[contains(@href,'https://www.reddit.com/login'"))))
但我收到此错误消息:
Traceback (most recent call last):
File "C:\Users\mmetral\Desktop\PhoneBot\PhoneBotV3\modules\robots\reddit\Reddit_Browser_Bot.py", line 510, in <module>
RunRedditBrowser(p_browser, p_driver, p_function, p_taskuser_id,label_log,lock)
File "C:\Users\mmetral\Desktop\PhoneBot\PhoneBotV3\modules\robots\reddit\Reddit_Browser_Bot.py", line 441, in RunRedditBrowser
AreWeRedditLoggedIn(p_driver)
File "C:\Users\mmetral\Desktop\PhoneBot\PhoneBotV3\modules\robots\reddit\Reddit_Browser_Bot.py", line 193, in AreWeRedditLoggedIn
button_LogIn = WebDriverWait(p_driver, 10).until(EC.presence_of_element_located(
File "C:\Users\mmetral\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\support\wait.py", line 71, in until
value = method(self._driver)
File "C:\Users\mmetral\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\support\expected_conditions.py", line 64, in __call__
return _find_element(driver, self.locator)
File "C:\Users\mmetral\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\support\expected_conditions.py", line 415, in _find_element
raise e
File "C:\Users\mmetral\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\support\expected_conditions.py", line 411, in _find_element
return driver.find_element(*by)
File "C:\Users\mmetral\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 976, in find_element
return self.execute(Command.FIND_ELEMENT, {
File "C:\Users\mmetral\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\mmetral\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: Failed to write request to stream
Process finished with exit code 1
我在 google 中搜索此错误消息,但找不到任何内容。
有人可以帮助我吗?
解决方案
你使用的xpath
是错误的。尝试以下操作,按钮将被单击。
button_LogIn = WebDriverWait(p_driver, 10).until(EC.presence_of_element_located(
(By.XPATH, ("//*[@id='SHORTCUT_FOCUSABLE_DIV']/div[1]/header/div/div[2]/div/div[1]/a[1]"))))
# clicking the button
button_LogIn.click()
推荐阅读
- javascript - 如何在本机反应中使用stackNavigation和drawerNavigation并在stackNavigation组件中使用toggleDrawer()
- elasticsearch - logstash -> Elasticsearch:更新非规范化数据
- mybatis - Mybatis foreach之HashMap
- c++ - map::lower_bound() 和 map::upper_bound 如何在 C++ 中工作?
- javascript - Javascript:循环到任何带有偶数/奇数描述的数字。为什么它只记录用户输入?
- python - 快速创建具有序列号的列表
- javascript - Kotlin XML 解析
- sbt - 如何运行 sbt,评估表达式并离开?
- android - 如何使用 XmlPullParser Android 读取没有 StartTag 或 Endtag 的 XML 标记
- html - 电子邮件不在 Outlook 中居中