启动url后,有一封电子邮件弹出,我正在尝试关闭。我已经编写了xpath,并且能够用它找到关闭图标。但是当我尝试执行的时候,它并没有关闭。然后,我隐式添加了等待元素可见,然后尝试关闭。尽管如此,它仍然没有关闭。你能告诉我发生这种情况的原因是什么吗?如何解决?并且提交按钮也没有单击我给出了正确的xpath。
提前谢谢..
下面是代码片段。
public static void main(String[] args) {
WebDriver driver;
System.setProperty("webdriver.chrome.driver", "E:\\Softwares\\Chromedriver.exe");
driver = new ChromeDriver();
driver.get("https://html.com/input-type-file/");
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
WebElement closeButon = driver.findElement(By.xpath("//a[@class='om-close miami-element-close miami-close']"));
if(closeButon.isDisplayed())
{
System.out.println("close Buton is there.. ");
closeButon.click();
System.out.println("close Buton closed ");
}
driver.findElement(By.xpath("//input[@name='fileupload']")).sendKeys("E:\\Users\\laxman_p\\Desktop\\PromoFeature.txt");
//Submit buttondriver.findElement(By.xpath("//*@id='post-206'/div/div3/form/input2")).click();
}发布于 2018-09-26 22:28:13
如果你不能通过xpath关闭它,我认为这个问题可能与聚焦窗口有关,你需要使用getWindowHandle和switchTo方法来聚焦这个弹出窗口。之后,您将能够在此弹出窗口上进行处理。
driver.getWindowHandles() 返回窗口集。
driver.switchTo.window(windowId);将切换到您想要关注的窗口。
https://stackoverflow.com/questions/52518598
复制相似问题