【问题标题】:Trouble with Selenium and ChromeDriverSelenium 和 ChromeDriver 的问题
【发布时间】:2016-12-10 18:03:24
【问题描述】:

我正在尝试让 Selenium 工作,但我似乎无法弄清楚。我已经安装了正确的 Ruby gem,并且正在尝试执行此代码。

require "selenium-webdriver"

driver = Selenium::WebDriver.for :chrome
driver.navigate.to "http://google.com"

element = driver.find_element(:name, 'q')
element.send_keys "Hello WebDriver!"
element.submit

puts driver.title

driver.quit

我很确定我的问题是我没有正确连接 ChromeDriver。如何链接 Chrome 驱动程序以使其正常工作?它说我需要把它放在我的路径上。有人可以解释一下吗?

Here is what I downloaded.

另外,这是我得到的错误:

in `executable_path': Unable to find the chromedriver executable.

【问题讨论】:

    标签: ruby selenium selenium-chromedriver


    【解决方案1】:

    有一个Selenium::WebDriver::Chrome.driver_path= 方法允许指定 chromedriver 可执行文件:

    # Specify the driver path
    Selenium::WebDriver::Chrome.driver_path = "path/to/chromedriver.exe"
    
    # now instantiate chrome driver 
    driver = Selenium::WebDriver.for :chrome
    driver.navigate.to "http://google.com"
    
    element = driver.find_element(:name, 'q')
    element.send_keys "Hello WebDriver!"
    element.submit
    
    puts driver.title
    
    driver.quit
    

    【讨论】:

      【解决方案2】:

      放置chrome驱动取决于你的操作系统,检查this link:

      OS    Expected Location of Chrome
      Linux /usr/bin/google-chrome1
      Mac   /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome
      Windows XP    %HOMEPATH%\Local Settings\Application Data\Google\Chrome\Application\chrome.exe
      Windows Vista C:\Users\%USERNAME%\AppData\Local\Google\Chrome\Application\chrome.exe
      

      【讨论】:

        【解决方案3】:

        无法找到 chromedriver 可执行文件: 当系统无法找到 chromedriver 时,我们会得到这个。我们可以通过设置环境变量“webdriver.chrome.driver”帮助系统找到它 如果您正在运行 unix/linux,请使用 export webdriver.chrome.driver=<path_where_binary_is_present> 如果在 Windows 上运行: 转到系统高级环境变量。添加一个名称为 webdriver.chrome.driver 且值设置为二进制路径的条目

        我们也可以从程序中设置这个位置。就像在java中一样 System.setProperty("webdriver.chrome.driver", ""

        执行上述任何一项操作,此错误都会消失

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2020-04-02
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2018-06-25
          • 2020-01-05
          • 2020-09-16
          相关资源
          最近更新 更多