【JS逆向】如何一招彻底解决selenium WebDriver无响应

前言

selenium 无响应,最常见的原因是,webDriver与浏览器版本不匹配导致的。

而chrome 目前新的版本都是会自动升级的,这就会导致一段时间不用selenium时,driver就无法使用了。

1、检测情况

from selenium import webdriver
driver = webdriver.Chrome()

#测试方法
def query_selenium():
    driver.get("https://www.baidu.com")
    print(driver.title)

if __name__ == '__main__':
    query_selenium()

如果Driver不正常的话,会一直卡着,不会有响应,或者报错

或者是报这样一个错误

The chromedriver version (114.0.5735.90) detected in PATH at E:\workspace\python\test\venv\Scripts\chromedriver.exe might not be compatible with the detected chrome version (120.0.6099.130); currently, chromedriver 120.0.6099.109 is recommended for chrome 120.*, so it is advised to delete the driver in PATH and retry
Traceback (most recent call last):
  File "E:\workspace\python\test\gemini\gemini_gpt.py", line 33, in <module>
    driver = webdriver.Chrome()
  File "E:\workspace\python\test\venv\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 45, in __init__
    super().__init__(
  File "E:\workspace\python\test\venv\lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 56, in __init__
    super().__init__(
  File "E:\workspace\python\test\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 206, in __init__
    self.start_session(capabilities)
  File "E:\workspace\python\test\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 290, in start_session
    response = self.execute(Command.NEW_SESSION, caps)["value"]
  File "E:\workspace\python\test\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 345, in execute
    self.error_handler.check_response(response)
  File "E:\workspace\python\test\venv\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 229, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 114
Current browser version is 120.0.6099.130 with binary path C:\Program Files\Google\Chrome\Application\chrome.exe
Stacktrace:
Backtrace:
	GetHandleVerifier [0x0108A813+48355]
	(No symbol) [0x0101C4B1]
	(No symbol) [0x00F25358]
	(No symbol) [0x00F461AC]
	(No symbol) [0x00F41EF3]
	(No symbol) [0x00F40579]
	(No symbol) [0x00F70C55]
	(No symbol) [0x00F7093C]
	(No symbol) [0x00F6A536]
	(No symbol) [0x00F482DC]
	(No symbol) [0x00F493DD]
	GetHandleVerifier [0x012EAABD+2539405]
	GetHandleVerifier [0x0132A78F+2800735]
	GetHandleVerifier [0x0132456C+2775612]
	GetHandleVerifier [0x011151E0+616112]
	(No symbol) [0x01025F8C]
	(No symbol) [0x01022328]
	(No symbol) [0x0102240B]
	(No symbol) [0x01014FF7]
	BaseThreadInitThunk [0x75B2FCC9+25]
	RtlGetAppContainerNamedObjectPath [0x76F37C6E+286]
	RtlGetAppContainerNamedObjectPath [0x76F37C3E+238]


Process finished with exit code 1

2、重新下载新的Driver

最好的解决方案是,进入chromeDriver官方下载

访问ChromeDriver官方页面:ChromeDriver - WebDriver for Chrome - Downloads

官方展示如下:

我们查看Chrome版本可以看出,

版本号为120.0.6099.130 ,而官方出的driver 却给出的版本是 ChromeDriver 114.0.5735.90

选择 current releases 中的这个标红的链接,进入到测试版本选择里面。

选择最接近我们的 chrome版本的,能用的版本

从此处进行chromeDriver 下载

放入到python环境中去,

以下是测试结果 :

有想一起学习python爬虫的朋友,私聊

  • 14
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
amazon 3星+ 好评 Key Features Covers basic to advanced concepts of WebDriver Learn how to design a more effective automation framework Explores all of the APIs within WebDriver Acquire an in-depth understanding of each concept through practical code examples Book Description Selenium WebDriver is an open source web UI automation tool implemented through a browser-specific browser driver, which sends commands to a browser and retrieves results. Selenium WebDriver Practical Guide will guide you through the various APIs of WebDriver which should be used in automation tests, followed by a discussion of the various WebDriver implementations available. This guide will support you by offering you access to source code fi les, including the essential HTML fi les, that allow you to work with jQuery and other examples throughout the book. Finally, you will receive an in-depth explanation of how to deal with the latest features of WebDriver through step-by-step practical tutorials. What you will Learn Learn the basic design of Selenium WebDriver and understand how it overcomes the limitations of its predecessor Set up and use Selenium Grid Discover the various mechanisms used to locate web elements Perform advanced actions such as drag-and-drop, double-click, right-click, and action builders on web pages Explore the advanced features of WebDriver such as handling cookies, taking screenshotsmanaging timeouts, and browser navigations Acquire an understanding of the various WebDriver implementations such as Firefox Driver, IE Driver, and Chrome Driver Explore WebDriver EventListeners Design effective automation frameworks using the PageObject pattern Learn how to deal with the latest features of WebDriver About the Author Satya Avasarala has rich experience in Java development and automation testing. He is an engineer in computer science. He has used WebDriver for many years now and has created several good automation frameworks. He has worked at various large software enterprises such as Oracle Corp, Yahoo! Inc., VMware Inc., and the REA Group. Table of Contents Introducing WebDriver and WebElements Exploring Advanced Interactions of WebDriver Exploring the Features of WebDriver Different Available WebDrivers Understanding WebDriver Events Dealing with I/O Exploring RemoteWebDriver and WebDriverBackedSelenium Understanding Selenium Grid Understanding PageObject Pattern Testing iOS and Android Apps

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

lxtx-0510

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值