javascript技巧

关注公众号 jb51net

关闭
首页 > 网络编程 > JavaScript > javascript技巧 > selenium WebDriver无响应解决

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

作者:lxtx-0510

Selenium Webdriver是一款强大的自动化测试工具,用于模拟真实用户在浏览器中的交互行为,下面这篇文章主要给大家介绍了关于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环境中去,

以下是测试结果 :

总结 

到此这篇关于JS逆向之如何一招彻底解决selenium WebDriver无响应的文章就介绍到这了,更多相关selenium WebDriver无响应解决内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

您可能感兴趣的文章:
阅读全文