线程“main”中的异常org.openqa.selenium.WebDriverException:未知错误:无法获得自动化扩展

时间:2017-04-06 14:45:56

标签: java selenium selenium-chromedriver maximize-window

我正在尝试使用以下脚本登录页面,但在最大化窗口时它会向我显示错误。

  

线程“main”中的异常org.openqa.selenium.WebDriverException:未知错误:无法获得自动化扩展       来自未知错误:找不到页面:chrome-extension://aapnijgdinlhnhlmodcfapnahmbfebeb/_generated_background_page.html         (会话信息:chrome = 57.0.2987.133)         (驱动程序信息:chromedriver = 2.27.440174(e97a722caafc2d3a8b807ee115bfb307f7d2cfd9),platform = Windows NT 10.0.14393 x86_64)(警告:服务器未提供任何堆栈跟踪信息)       命令持续时间或超时:10.11秒       构建信息:版本:'3.3.1',修订版:'5234b32',时间:'2017-03-10 09:04:52 -0800'       系统信息:主机:'PRASANNAMULAY',ip:'172.21.31.80',os.name:'Windows 10',os.arch:'amd64',os.version:'10 .0',java.version:'1.8.0_121 “       驱动程序信息:org.openqa.selenium.chrome.ChromeDriver       Capabilities [{applicationCacheEnabled = false,rotate = false,mobileEmulationEnabled = false,networkConnectionEnabled = false,chrome = {chromedriverVersion = 2.27.440174(e97a722caafc2d3a8b807ee115bfb307f7d2cfd9),userDataDir = C:\ Users \ PRASAN~1 \ AppData \ Local \ Temp \ scoped_dir12528_8422} ,takesHeapSnapshot = true,pageLoadStrategy = normal,databaseEnabled = false,handlesAlerts = true,hasTouchScreen = false,version = 57.0.2987.133,platform = XP,browserConnectionEnabled = false,nativeEvents = true,acceptSslCerts = true,locationContextEnabled = true,webStorageEnabled = true ,browserName = chrome,takesScreenshot = true,javascriptEnabled = true,cssSelectorsEnabled = true,unexpectedAlertBehaviour =}]       会话ID:947fe656f81e3ced5cf5c932e81bc2f8           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)           在org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:216)           在org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:168)           在org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:638)           在org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:661)           在org.openqa.selenium.remote.RemoteWebDriver $ RemoteWebDriverOptions $ RemoteWindow.maximize(RemoteWebDriver.java:895)           at pract_1_phase_3.Pract_1_phase_3.main(Pract_1_phase_3.java:48)

------------------------------------------------------------------------------------

My code is:-
package pract_1_phase_3;

import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;
import java.util.HashMap;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.interactions.Action;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.FluentWait;
import org.openqa.selenium.support.ui.Wait;

import com.google.common.base.Function;

public class Pract_1_phase_3 {

    public static void main(String[] args)throws AWTException {

    //  System.setProperty("webdriver.gecko.driver","D:\\Gecko\\geckodriver.exe");


        ChromeOptions options = new ChromeOptions();

        Map<String, Object> prefs = new HashMap<String, Object>();
        prefs.put("credentials_enable_service", false);
        prefs.put("password_manager_enabled", false); 
        options.setExperimentalOption("prefs", prefs);

        ChromeDriver driver = new ChromeDriver(options);

        driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);

        driver.get("http://demo.actitime.com/");

        driver.manage().window().maximize();

        driver.findElement(By.name("username")).sendKeys("admin");

        driver.findElement(By.name("pwd")).sendKeys("manager");

        driver.findElement(By.id("loginButton")).click();

Please tell me whats steps i need to do to resolve above issue

Thanks in advance

4 个答案:

答案 0 :(得分:2)

升级到最新的chromedriver。

这是一个错误,并在chromedriver v2.28中得到了解决。 请参阅:https://sites.google.com/a/chromium.org/chromedriver/downloads

答案 1 :(得分:1)

我最近也面临同样的问题。我从https://chromedriver.storage.googleapis.com/index.html?path=2.29/拿了最新的jar并添加到我的项目中。问题得到了解决。

答案 2 :(得分:0)

尝试:

System.setProperty("webdriver.chrome.driver", "\\path\\to\\chromedriver");

并且不要将selenium.jar添加到您的构建路径

答案 3 :(得分:0)

屏幕闪烁也可能导致此错误。

解决方案将窗口大小缩小到屏幕变得稳定。 我可以通过添加以下代码来解决此问题

 Dimension d = new Dimension(800, 600);
 driver.manage().window().setSize(d);