【问题标题】:Selenium webdriver is opening the browser, but not opening the given urlSelenium webdriver 正在打开浏览器,但没有打开给定的 url
【发布时间】:2020-08-13 11:27:34
【问题描述】:

This is the screenshot of the error I'm getting.

我最近承担了使用 selnium webdriver 和 python 来学习功能测试和 Web 自动化的任务。当我执行我的代码时,Web 浏览器会打开,但 URL 不会。我已经尝试了互联网上的所有建议,例如:更新 chrome、尝试不同的 IDE、使用 FireFox。这些都没有帮助我的代码执行我想要的。

from selenium import webdriver

from selenium.webdriver.common.keys import Keys

chrome = webdriver.Chrome(executable_path='/Applications/Google Chrome.app/Contents/MacOS/Google Chrome')

chrome.get('https://www.youtube.com/watch?v=oM-yAjUGO-E')

【问题讨论】:

  • executable_path 应该指向chromedriver 位置。你确定你说的是正确的位置吗?
  • 该位置可能是正确的,因为浏览器打开了,但如果不是,我如何在 Mac 上找到该位置。 @0buz
  • 如果你在终端输入which chromedriver,输出是什么?
  • 你指的是哪个终端?
  • 命令提示符terminal.

标签: python selenium selenium-webdriver webautomation


【解决方案1】:

对于遇到此问题的任何人,请确保您已安装 chromedriver(或您的浏览器可用的任何驱动程序)。对于 chrome,您首先需要检查您的信息并从 chrome://version/ 中找出版本 然后来自https://sites.google.com/a/chromium.org/chromedriver/downloads 下载对应的驱动,将文件路径复制到executable_path部分。

【讨论】:

    【解决方案2】:

    确保您已安装chromedriver。 安装路径通常是“/usr/local/bin”,尽管无论路径如何,都可以用作“executable_path”

    还记得保留 Chrome 浏览器和 chromedriver 版本in sync,即如果你有 Chrome 版本 81,你应该安装 chromedriver 版本 81。

    【讨论】:

      猜你喜欢
      • 2016-04-03
      • 2016-10-16
      • 2018-04-01
      • 2017-01-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-08
      相关资源
      最近更新 更多