java 从 Selenium 触发时,谷歌浏览器无法导航到指定的 URL

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29506731/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 15:23:40  来源:igfitidea点击:

Google Chrome unable to navigate to specified URL when triggered from Selenium

javagoogle-chromeseleniumautomationselenium-chromedriver

提问by Razvi

I have an automation framework developed around Selenium-WebDriver which launches Chrome and navigates to specified URL and performs specified automation. When I commissioned the framework to perform a long task and left it overnight to run (Run was not successful). The following day when I tried to re-run a new set of Tests, Selenium was able to fire Chrome but the Browser would not navigate to the specified URL. The following is the detailed stack trace.

我有一个围绕 Selenium-WebDriver 开发的自动化框架,它启动 Chrome 并导航到指定的 URL 并执行指定的自动化。当我委托框架执行一项长期任务并让它过夜运行时(运行未成功)。第二天,当我尝试重新运行一组新测试时,Selenium 能够启动 Chrome,但浏览器无法导航到指定的 URL。以下是详细的堆栈跟踪。

Starting ChromeDriver (v2.7.236900) on port 60678
Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: cannot get automation extension from unknown error: page could not be found: chrome-extension://aapnijgdinlhnhlmodcfapnahmbfebeb/_generated_background_page.html
(Session info: chrome=41.0.2272.118)
(Driver info: chromedriver=2.7.236900,platform=Windows NT 6.3 x86_64)   (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 10.12 seconds
Build info: version: '2.24.1', revision: '17205', time: '2012-06-19 16:53:24'
System info: os.name: 'Windows 8.1', os.arch: 'x86', os.version: '6.3', java.version: '1.8.0_25'
Driver info: driver.version: RemoteWebDriver
Session ID: a2fafed66d51994e3ef57bada99fddbf
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:188)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:472)
at org.openqa.selenium.remote.RemoteWebDriver$RemoteWebDriverOptions$RemoteWindow.maximize(RemoteWebDriver.java:683)
at com.gravitant.utils.Util.launchBrowser(Util.java:1711)
at com.gravitant.test.RunTests.start(RunTests.java:147)
at com.gravitant.test.RunTests.main(RunTests.java:80)

This is the second time I am facing the same issue. When I tried to google search the error I was able find thisparticular forum. I tried to re-download Chrome_driver but it did not help. Restarting the system did not help either. I double checked the code and all the set-up but nothing was changed. Curiously I was able to stumble upon a curious solution.

这是我第二次面临同样的问题。当我尝试谷歌搜索错误时,我能够找到这个特定的论坛。我尝试重新下载 Chrome_driver,但没有帮助。重新启动系统也没有帮助。我仔细检查了代码和所有设置,但没有任何改变。奇怪的是,我偶然发现了一个奇怪的解决方案。

Solution - Re-installing Chrome Browser solved the issue. I was able to run the tests perfectly.

解决方案 - 重新安装 Chrome 浏览器解决了该问题。我能够完美地运行测试。

I am curious to understand why this was and what might have caused chrome to behave so oddly.

我很想知道为什么会这样,以及什么可能导致 chrome 表现得如此奇怪。

采纳答案by Razvi

The issue here is, Selenium-WebDriver is unable to launch the installed 3rd Party Extensions in chrome. I encountered the issue today as well, so instead of re-installing google chrome, I deleted all the extensions I had installed on Chrome. I have a couple of "Add Blocker" extensions installed.

这里的问题是,Selenium-WebDriver 无法在 chrome 中启动已安装的 3rd Party Extensions。我今天也遇到了这个问题,所以我没有重新安装谷歌浏览器,而是删除了我在 Chrome 上安装的所有扩展程序。我安装了几个“添加阻止程序”扩展。

回答by Victor Trofimciuc

In my case, the chrome browser version and chromedriver versions were incompatible. Chrome updated automatically from 56 to 57 and my chromedriver version was 2.27. The 2 issues throwing 'org.openqa.selenium.WebDriverException: unknown error: cannot get automation extension' error (when maximizing the browser and when taking screenshots), where fixed after updating to cromdriver version 2.28.

就我而言,chrome 浏览器版本和 chromedriver 版本不兼容。Chrome 自动从 56 更新到 57,我的 chromedriver 版本是 2.27。抛出“org.openqa.selenium.WebDriverException:未知错误:无法获得自动化扩展”错误的 2 个问题(在最大化浏览器和截屏时),在更新到 cromdriver 版本 2.28 后修复。

回答by VaraPrasad Pakalapati

Reason for the exception is chrome failed to load selenium automation extension.

异常的原因是chrome 无法加载 selenium 自动化扩展

When ever selenium opens chrome browser, selenium loads a chrome extension in chrome browser to work with it from some temp location. If chrome browser failed to load that extension it will throw an exception.

当 selenium 打开 chrome 浏览器时,selenium 会在 chrome 浏览器中加载一个 chrome 扩展程序,以便从某个临时位置使用它。如果 Chrome 浏览器无法加载该扩展程序,它将引发异常。

I got the same exception when my organization blocked loading third party extensions in my chrome browser.

当我的组织阻止在我的 chrome 浏览器中加载第三方扩展程序时,我遇到了同样的异常。

Test method 
Veolia.BrentGWP.UserStories.Features.BrentGWPFeature._3_EnterDetailsAndSelectAnAddress_John threw exception: 
System.InvalidOperationException: unknown error: cannot get automation extension
from unknown error: page could not be found: chrome-  extension://aapnijgdinlhnhlmodcfapnahmbfebeb/_generated_background_page.html
(Session info: chrome=41.0.2272.118)
(Driver info: chromedriver=2.9.248315,platform=Windows NT 6.1 SP1 x86_64)

I am using Selenium with C# and Visual Studio.

我在 C# 和 Visual Studio 中使用 Selenium。

回答by Pratik Patel

I was facing the same issue, In my case the main problem was:

我面临同样的问题,就我而言,主要问题是:

Incompatibility between chrome version and chromedriver version.

chrome 版本和 chromedriver 版本不兼容。

Chrome browser is self upgraded, it updates to latest version automatically (In most of case).

Chrome 浏览器是自我升级的,它会自动更新到最新版本(在大多数情况下)。

So you need to upgrade chromedriverversion periodicallyand there are release notes are also available which describes the compability between chromedriver and chrome version.

因此,您需要定期升级chromedriver版本,并且还提供发布说明,其中描述了 chromedriver 和 chrome 版本之间的兼容性。

回答by Chris Liston

I had this on my Windows 10 (64 bit) PC after upgrading to Selenium 3.3.1. Downloading Chromedriver 2.29 and overwriting the old version worked. See - https://chromedriver.storage.googleapis.com/index.html?path=2.29/

升级到 Selenium 3.3.1 后,我在 Windows 10(64 位)PC 上安装了这个。下载 Chromedriver 2.29 并覆盖旧版本有效。请参阅 - https://chromedriver.storage.googleapis.com/index.html?path=2.29/

回答by Xing.Kyrie

I found this problem is chromedriver version cause. My case run ok when i update the chromedriver.

我发现这个问题是 chromedriver 版本的原因。当我更新 chromedriver 时,我的案例运行正常。

回答by Sreedhar Puttagunta

In case someone is still looking for an answer. Here is the matching response for my situation. https://github.com/SeleniumHQ/selenium/issues/3508This exactly what is happening in my case where, I'm getting it 60-70% of the time when maximize is called

如果有人仍在寻找答案。这是针对我的情况的匹配响应。 https://github.com/SeleniumHQ/selenium/issues/3508这正是在我的情况下发生的事情,当调用最大化时,我有 60-70% 的时间得到它

org.openqa.selenium.remote.RemoteWebDriver$RemoteWebDriverOptions$RemoteWindow.maximize(RemoteWebDriver.java:945)
at org.openqa.selenium.support.events.EventFiringWebDriver$EventFiringWindow.maximize(EventFiringWebDriver.java:644)
at org.openqa.selenium.remote.server.handler.MaximizeWindow.call(MaximizeWindow.java:30)
at org.openqa.selenium.remote.server.handler.MaximizeWindow.call(MaximizeWindow.java:1)