python - Selenium 无法打开指定的 URL 并显示数据 :,

标签 python selenium google-chrome selenium-webdriver selenium-chromedriver

我正在尝试在 Chrome 中使用 selenium 打开 URL。我有 chromedriver 可用。

以下是我要执行的代码。

from selenium import webdriver

chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--disable-infobars")

driver = webdriver.Chrome(executable_path="./chromedriver", chrome_options=chrome_options)
driver.get("https://google.com")

浏览器已成功打开,但未打开指定的 URL。浏览器中的 URL 为 data:,

任何帮助将不胜感激。请!

请参阅附图。

注意:Selenium 版本:3.14.0

enter image description here

关闭 chrome 选项卡时出现以下错误。

File "test.py", line 6, in <module>
    driver = webdriver.Chrome(executable_path="./chromedriver", chrome_options=chrome_options)
  File "/home/speedious/anaconda3/lib/python3.5/site-packages/selenium/webdriver/chrome/webdriver.py", line 75, in __init__
    desired_capabilities=desired_capabilities)
  File "/home/speedious/anaconda3/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 156, in __init__
    self.start_session(capabilities, browser_profile)
  File "/home/speedious/anaconda3/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 251, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/home/speedious/anaconda3/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 320, in execute
    self.error_handler.check_response(response)
  File "/home/speedious/anaconda3/lib/python3.5/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited normally
  (chrome not reachable)
  (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
  (Driver info: chromedriver=2.42.591071 (0b695ff80972cc1a65a5cd643186d2ae582cd4ac),platform=Linux 4.10.0-37-generic x86_64)

最佳答案

此错误消息...

selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited normally
  (chrome not reachable)
  (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)

...表示 ChromeDriver 实例无法启动 Chrome 浏览器 进程。

您的主要问题是 google-chrome 不再出现在预期的默认位置 /usr/bin/

根据 ChromeDriver - Requirements服务器希望您将 Chrome 安装在每个系统的默认位置:

Chrome_binary_expected_location

1 对于 Linux 系统,ChromeDriver 期望/usr/bin/google-chrome 是实际 Chrome 二进制文件的符号链接(symbolic link)。您还可以覆盖 Chrome 二进制文件位置,如下所示:

  • 基于 Windows 操作系统的示例:

    from selenium import webdriver
    from selenium.webdriver.chrome.options import Options
    
    options = Options()
    options.add_argument("start-maximized")
    options.binary_location("C:\\path\\to\\chrome.exe")
    driver = webdriver.Chrome(executable_path=r'C:\path\to\chromedriver.exe', chrome_options=options)
    driver.get('http://google.com/')
    

其他注意事项

  • ChromeDriver升级到当前的ChromeDriver v2.42级别。
  • Chrome 版本保持在 Chrome v68-70 级别之间。 (as per ChromeDriver v2.42 release notes)
  • 通过IDE清理您的项目工作区,并仅使用所需的依赖项重建项目。
  • 如果您的基本网络客户端版本太旧,请通过 Revo Uninstaller 卸载它并安装最新的 GA 和已发布版本的Web 客户端
  • 执行您的@Test

关于python - Selenium 无法打开指定的 URL 并显示数据 :,,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59639078/

相关文章:

c# - python:math.sqrt(x) 函数有多准确?

python - 如何在 lion 上安装 Cython

c# - 如何使用 Selenium、Webdriver、C# 在 Esri map 上绘制多边形

selenium - 登录Gmail帐户失败(Selenium Automation)

html - 边框不在 Chrome PDF 查看器中打印

image - 大图像无法在 Chrome 中呈现?

python - 如何将 parser.addoption 放在测试模块中,而不是放在 conftest.py 中?

python - 将 Elmo 与 tf.Keras 一起使用会引发 ValueError : could not convert string to float

java - Gitlab ci selenium testing with docker not connecting to RemoteWebDriver

java - Headless Chrome --print-to-pdf 与亚洲字体