Selenium - mobileEmulation not working after chromedriver version updation to 2.30

时间:2017-06-15 10:07:10

标签: selenium selenium-chromedriver

Below code is working fine, when I use chromedriver ver 2.28 but giving me below error when I use Chromedriver ver 2.30

Stack-trace:

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

Code:

    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);

1 个答案:

答案 0 :(得分:8)

该设备似乎已重命名为“Nexus 5”。

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

  • BlackBerry Z30
  • Blackberry PlayBook
  • Galaxy Note 3
  • Galaxy Note II
  • Galaxy S III
  • Kindle Fire HDX
  • LG Optimus L70
  • 具有HiDPI屏幕的笔记本电脑
  • 具有MDPI屏幕的笔记本电脑
  • 触控笔记本电脑
  • Microsoft Lumia 550
  • Microsoft Lumia 950
  • Nexus 10
  • Nexus 4
  • Nexus 5
  • Nexus 6
  • Nexus 7
  • 诺基亚Lumia 520
  • 诺基亚N9
  • iPad Mini
  • iPhone 4
  • Galaxy S5
  • Nexus 5X
  • Nexus 6P
  • iPhone 5
  • iPhone 6
  • iPhone 6 Plus
  • ipad公司