移动设备的Selenium问题

2024-06-12 15:25:14 发布

您现在位置:Python中文网/ 问答频道 /正文

我面临一个例外,我需要打开一个新窗口,但新窗口在IOS或android设备中无法打开。你知道吗

在Chrome Ie和带有Windows的Firefox中工作得非常好。你知道吗

代码

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

Tags: ofthecomtargetgetstringvaluedriver
1条回答
网友
1楼 · 发布于 2024-06-12 15:25:14

我在移动设备上运行测试时也遇到了同样的问题。经过多次尝试,我发现是窗户大小造成的。你知道吗

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

相关问题 更多 >