无法使用Selenium打开网站(Chrome,Firefox)

时间:2017-04-05 07:46:23

标签: google-chrome selenium firefox

两天后,我的PC上再也无法通过Selenium WebDriver(Java,Maven,IntelliJ)打开带有firefox的网站。在新的Firefox窗口中打开一个空白页面,没有任何反应。我可以在打开的firefox窗口中手动访问指定的网站。

这是我用来创建webdriver的代码(配置文件SELENIUM存在;我是手动创建的):

System.setProperty("webdriver.gecko.driver", "geckodriver.exe");
ProfilesIni profile = new ProfilesIni();
FirefoxProfile ffprofile = profile.getProfile("SELENIUM");
return new FirefoxDriver(ffprofile);

打开我正在使用的页面:

driver.get(myURL);

IntelliJ的错误消息是:

  

SZgNd84ad1sbgGXU5f5p + 46dwuqwWXX8hUp4lAPBZwEAAA0DAAANAAAAAAAAAAAAAAAAALfGQwB4dWxzdG9yZS5qc29uUEsFBgAAAABGAEYAnRUAAFnIQwAAAA(和一些百万多个字母)==不等于未定义“](警告:服务器没有提供任何堆栈跟踪信息)   命令持续时间或超时:0毫秒

今天Chrome也停止了工作,它只在网址和数据旁边显示“不安全”;在URL栏中。 有没有办法找出导致这种情况的原因以及如何解决这个问题? 我使用的是最新版本的selenium(在pom.xml中定义)Chrome版本57.0.2987.133,Firefox 45.4.0。

提前感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

我在之前的项目中已经看到了这一点,所以基本上发生的是所有这些都是由Selenium和Firefox / Chrome版本之间的不兼容引起的,而不是由任何一个特定的版本号引起的。因此,如果您的WebDriver是最新版本,那么您真正想要的是最新版本的1-2个驱动程序版本。否则,如果WebDriver较旧,则将Firefox / Chrome版本更进一步,或升级Webdriver。

其他选项是使用FF profiles / Chrome preferences。这是一个当时有效的例子:

FirefoxProfile prof = new FirefoxProfile();
//FirefoxProfile prof = profile.getProfile("default");
//prof.setPreference("browser.startup.homepage", pageUrl);
//prof.setPreference("startup.homepage_welcome_url", pageUrl);
//prof.setPreference("startup.homepage_welcome_url.additional", pageUrl);
prof.setPreference("xpinstall.signatures.required", false);
prof.setPreference("toolkit.telemetry.reportingpolicy.firstRun", false);

您可以尝试这些设置的其他组合,看看哪种设置适合您。