【问题标题】:Issue With Selenium For Mobile Devices移动设备的硒问题
【发布时间】:2016-06-09 13:21:35
【问题描述】:

我遇到了一个异常,我需要打开一个新窗口,但新窗口没有在 IOS 或 android 设备中打开。

它在 Chrome Ie 和 Firefox 与 Windows 中运行良好。

代码

driver.get("http://testdroid.com/tech/the-basics-of-mobile-web-testing-using-appium-selenium");
driver.findElement(By.xpath("//a[contains(text(),'Latest')]")).click();

String target="https://wiki.saucelabs.com/display/DOCS/Platform+Configurator#/";
String value="testEnrollWindow";


String parentHandle = driver.getWindowHandle(); // get the current window handle

String args1 = String.format("window.open('%s', '%s'); null;", target, value);
((JavascriptExecutor) driver).executeScript(args1);
driver.manage().window().maximize();

for (String winHandle : driver.getWindowHandles()) {
    driver.switchTo().window(winHandle); // switch focus of WebDriver to the next found window handle (that's your newly opened window)
}

driver.close(); // close newly opened window when done with it
driver.switchTo().window(parentHandle); // switch b

【问题讨论】:

  • 提及异常。可能您的移动驱动不支持该操作
  • 那里没有任何异常,但没有发生切换。

标签: java python ruby selenium selenium-webdriver


【解决方案1】:

我在移动设备上运行测试时遇到了同样的问题。经过多次尝试和尝试,我发现这是导致它的窗口大小。

所以删除driver.manage().window().maximize();

【讨论】:

  • 即使在我删除该代码后仍然面临同样的异常。如果我打印 getWindowHandles(),我只会得到 1 作为输出,预计会是 2。
  • 我什至没有看到异常但没有打开新窗口。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-05-22
  • 2020-07-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-03-26
相关资源
最近更新 更多