简体   繁体   English

如何使用 Selenium Java 在警报弹出窗口中单击复选框

[英]How to click a checkbox in an alert popus using Selenium Java

guys I cannot find a solution of the clicking (unclicking) a checkbox placed in an alert window, modal pop-ups.伙计们,我找不到单击(取消单击)放置在警报 window、模式弹出窗口中的复选框的解决方案。 We have three types pop-up: alert, confirm, prompt.我们有三种类型的弹出窗口:警报、确认、提示。 In the confirm popup there is a checkbox.在确认弹出窗口中有一个复选框。 I want to check it using selenium webdriver and java language.我想使用 selenium webdriver 和 java 语言检查它。 There are functions handling these popups: dismiss(), accept(), sendKeys(), getText().有处理这些弹出窗口的函数:dismiss()、accept()、sendKeys()、getText()。 Is it possible to check the checkbox in popups?是否可以检查弹出窗口中的复选框? I hope, it's.我希望,是的。 Could anybody help me?有人可以帮助我吗? thanks谢谢

You can do it with two ways你可以通过两种方式做到这一点

1) 1)

driver.switchTo().alert();
driver.findElement(By.xpath("")).click();

Put your locator in above code将您的定位器放在上面的代码中

2) 2)

If above doesn't work then as below:如果以上不起作用,则如下:

String parentWindowHandler = driver.getWindowHandle(); // Store your parent window
String subWindowHandler = null;

Set<String> handles = driver.getWindowHandles(); // get all window handles
Iterator<String> iterator = handles.iterator();
while (iterator.hasNext()){
    subWindowHandler = iterator.next();
}
driver.switchTo().window(subWindowHandler); // switch to popup window

driver.findElement(By.xpath("")).click();

driver.switchTo().window(parentWindowHandler);  // switch back to parent window

If even that doesn't work check if there is any frame present, you need to switch to frame also如果即使这样也不起作用检查是否存在任何框架,您还需要切换到框架

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM