我一直在尝试使用selenium点击/点击上的一个链接,这会在ipad/iphone上打开一个新的标签。我写的这个测试在台式机上运行得很好,但在ipad/iphone (saucelab)上运行时,它不会点击元素。单击元素的步骤被传递(没有错误),但没有发生单击,并且只有一个窗口句柄(父窗口)可用。当我尝试手动单击元素时(在saucelab上也是在物理设备上),它工作得很好&新选项卡打开。尝试了不同的定位器&都正确地识别了元素。尝试了不同的方法,如javascript,actions,TouchActions,长按和释放,甚至发送键。我在其他网站上也观察到了同样的行为。
这似乎是一个一般性的问题。请帮我解决这个问题。
谷歌类似的场景: Verify点击"https://www.google.com/gmail/about/policy/“页面上的”谷歌服务条款“链接,会打开一个新的标签。
代码段
driverThread.get().get("https://www.google.com/gmail/about/policy/");
String parentHandle = driverThread.get().getWindowHandle();
System.out.println("Parent Handle --- " + parentHandle);
WebElement element = driverThread.get().findElement(By.cssSelector("body > main > section > section > div > p:nth-child(2) > a"));
element.click(); // **please help me to click/tap this element**
String newHandle = null;
System.out.println("Window Handles size --- " + driverThread.get().getWindowHandles().size());
for (String handle : driverThread.get().getWindowHandles()) {
System.out.println("Handle --- " + handle);
if(!handle.equalsIgnoreCase(parentHandle))
newHandle = handle;
}
driverThread.get().switchTo().window(newHandle);
System.out.println("New Tab URL --- "+ driverThread.get().getCurrentUrl());
发布于 2018-04-18 16:03:25
您可以使用以下代码来单击该链接:
WebElement element = driverThread.get().findElement(By.linkText("Google’s Terms of Service"));
element.click();
试试这段代码吧!希望这能帮助你解决你的问题。
https://stackoverflow.com/questions/49890486
复制相似问题