Selenium - 在chromedriver版本更新到2.30后,mobileEmulation无法正常工作

Abh*_*yal 4 selenium selenium-chromedriver

下面的代码工作正常,当我使用chromedriver ver 2.28但是当我使用Chromedriver ver 2.30时给出以下错误

堆栈跟踪:

org.openqa.selenium.WebDriverException: unknown error: cannot parse 
capability: chromeOptions
from unknown error:  cannot parse mobileEmulation
from unknown error: 'Google Nexus 5' must be a valid device
from unknown error:  must be a valid device
Run Code Online (Sandbox Code Playgroud)

码:

    String chromedriver = CONFIG.getProperty("chromedriverpath");
    System.setProperty("webdriver.chrome.driver", chromedriver);

    Map<String, String> mobileEmulation = new HashMap<String, String>();
    mobileEmulation.put("deviceName", "Google Nexus 5");

    Map<String, Object> chromeOptions = new HashMap<String, Object>();
    chromeOptions.put("mobileEmulation", mobileEmulation);
    chromeOptions.put("args", Arrays.asList("--disable-extensions",
            "no-sandbox", "--allow-running-insecure-content", "ignore-
     certificate-errors","disable-infobars"));

    DesiredCapabilities capabilities = DesiredCapabilities.chrome();
    capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);

    WebDriver driver = new ChromeDriver(capabilities);
Run Code Online (Sandbox Code Playgroud)

Flo*_* B. 9

该设备似乎已重命名为"Nexus 5".

因此,要么创建自定义设备,要么使用开发工具中的列表中的设备:

  • 黑莓Z30
  • 黑莓PlayBook
  • Galaxy Note 3
  • Galaxy Note II
  • Galaxy S III
  • Kindle Fire HDX
  • LG Optimus L70
  • HiDPI屏幕的笔记本电脑
  • 带有MDPI屏幕的笔记本电脑
  • 触摸笔记本电脑
  • 微软Lumia 550
  • 微软Lumia 950
  • Nexus 10
  • Nexus 4
  • Nexus 5
  • Nexus 6
  • Nexus 7
  • 诺基亚Lumia 520
  • 诺基亚N9
  • 小型平板电脑
  • iPhone 4
  • Galaxy S5
  • Nexus 5X
  • Nexus 6P
  • iphone 5
  • iPhone 6
  • iPhone 6 Plus
  • iPad的