我试图用一个URL启动chrome浏览器,浏览器启动后,它什么也不做。

1分钟后我看到如下错误:

Unable to open browser with url: 'https://www.google.com' (Root cause: org.openqa.selenium.WebDriverException: unknown error: DevToolsActivePort file doesn't exist
  (Driver info: chromedriver=2.39.562718 (9a2698cba08cf5a471a29d30c8b3e12becabb0e9),platform=Windows NT 10.0.15063 x86_64) (WARNING: The server did not provide any stacktrace information)

我的配置:

Chrome浏览器:66 ChromeBrowser: 2.39.56

又及,在Firefox中一切都很好


当前回答

我遇到了同样的问题,我使用UBUNTU, PYTHON和OPERA浏览器。在我的例子中,这个问题是因为我有一个过时的operadriver版本。

解决方案: 1. 确保您安装了最新的opera浏览器版本(不要使用opera beta或opera developer),为此请到opera官方网站并从那里下载最新的opera_stable版本。

安装最新的opera驱动程序(如果你已经安装了一个opera驱动程序,你必须先使用sudo rm删除它…)

wget https://github.com/operasoftware/operachromiumdriver/releases/download/v.80.0.3987.100/operadriver_linux64.zip

   unzip operadriver_linux64.zip
   sudo mv operadriver /usr/bin/operadriver
   sudo chown root:root /usr/bin/operadriver
   sudo chmod +x /usr/bin/operadriver

在我的情况下,最新的是80.0.3987,你可以看到

此外,我还安装了chromedriver(但因为我在测试之前做了,我不知道这是需要的),为了安装chromedriver,遵循上一步的步骤 好好享受吧,谢谢我!

示例硒代码

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Opera()
driver.get("http://www.python.org")
assert "Python" in driver.title
elem = driver.find_element_by_name("q")
elem.clear()
elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)
assert "No results found." not in driver.page_source
driver.quit()

其他回答

更新:

我能够通过这个问题,现在我能够访问chrome所需的url。

对所提供解决方案的尝试结果:

我尝试了上面提供的所有设置,但我无法解决这个问题

关于问题的解释:

根据我的观察,DevToolsActivePort文件不存在的原因是chrome无法在scoped_dirXXXXX文件夹中找到它的引用。

为解决该问题所采取的步骤

我已经杀死了所有的chrome进程和chrome驱动程序进程。 添加下面的代码来调用chrome System.setProperty(“webdriver.chrome.driver”、“pathto \ \ chromedriver.exe”); ChromeOptions选项=新的ChromeOptions(); 选项。setExperimentalOption(“useAutomationExtension”,假); WebDriver驱动=新的ChromeDriver(选项); driver.get (url);

使用上述步骤,我能够解决这个问题。

谢谢你的回答。

没有解决方法对我有效。但这里有一个变通办法:

maxcounter=5
for counter in range(maxcounter):
    try:           
        driver = webdriver.Chrome(chrome_options=options,
                          service_log_path=logfile,
                          service_args=["--verbose", "--log-path=%s" % logfile])
        break
    except WebDriverException as e:
        print("RETRYING INITIALIZATION OF WEBDRIVER! Error: %s" % str(e))
        time.sleep(10)
        if counter==maxcounter-1:
            raise WebDriverException("Maximum number of selenium-firefox-webdriver-retries exceeded.")

我在与jenkins服务器集成时也遇到了这个问题,我使用了jenkin工作的根用户,当我将用户更改为其他用户时,这个问题得到了解决。我不确定为什么根用户会出现这个错误。

谷歌Chrome浏览器版本71.0 ChromeDriver版本2.45 CentOS7版本1.153

核心的答案 正确的解决方案:不使用root用户运行Chrome二进制 更多细节请参考另一个帖子的回答:未知错误:DevToolsActivePort文件不存在

我在python中遇到了同样的问题。以上这些都有帮助。这是我在python中使用的

chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
driver = webdriver.Chrome('/path/to/your_chrome_driver_dir/chromedriver',chrome_options=chrome_options)