Java 我想通过SeleniumWeb驱动程序在我的web应用程序中选中RadioType复选框,只要它可用
只要可用,我想通过selenium web驱动程序在我的web应用程序中选中radio type复选框 HTML: 我也尝试过:在这种情况下,单选按钮被选中,但在其他情况下不被忽略Java 我想通过SeleniumWeb驱动程序在我的web应用程序中选中RadioType复选框,只要它可用,java,selenium-webdriver,Java,Selenium Webdriver,只要可用,我想通过selenium web驱动程序在我的web应用程序中选中radio type复选框 HTML: 我也尝试过:在这种情况下,单选按钮被选中,但在其他情况下不被忽略 if (idYes.isElementPresentAndDisplayed()){ ((JavascriptExecutor)driver).executeScript("arguments[0].checked = true", idYes.isElementPresentAndDispl
if (idYes.isElementPresentAndDisplayed()){
((JavascriptExecutor)driver).executeScript("arguments[0].checked = true", idYes.isElementPresentAndDisplayed());
idYes.click();}
或另一次尝试:在这种情况下,未选择单选按钮
if (idYes.isElementPresentAndDisplayed()){
((JavascriptExecutor)driver).executeScript("arguments[0].checked = true", idYes.isElementPresentAndDisplayed());
idYes.clickIfElement Present();}
但当上述元素在不同的场景中不可用时,它就失败了。
预期的行为是:如果元素存在,请选择或忽略。将代码放入try-catch块。在catch块中,忽略发生的任何错误 e、 g
希望有帮助。您也可以这样做:
WebDriverWait wait = new WebDriverWait(driver, 10); // Have a wait object with 10 sec(or whatever u prefer) to enforce on driver object stating for max time it should wait for the conditions
try{
wait.until(ExpectedConditions.elementToBeClickable(By.id("idYes"))).click(); // will explicitly wait for the element to be clickable, else throw timeout exception
}catch(TimeoutException toe){
System.out.println("Check box not present, hence skipping. " + toe); // here you can log or sysout the reason for skipping accompanied with exception
}
if (idYes.isElementPresentAndDisplayed()){
((JavascriptExecutor)driver).executeScript("arguments[0].checked = true", idYes.isElementPresentAndDisplayed());
idYes.clickIfElement Present();}
try{
WebElement idYes = driver.findElement(By.id("idYes"));
if (idYes.isElementPresentAndDisplayed())
((JavascriptExecutor)driver).executeScript("arguments[0].checked = true",idYes.isElementPresentAndDisplayed());
idYes.click();
}catch(org.openqa.selenium.NoSuchElementException ignore){
//TODO: do nothing
}
WebDriverWait wait = new WebDriverWait(driver, 10); // Have a wait object with 10 sec(or whatever u prefer) to enforce on driver object stating for max time it should wait for the conditions
try{
wait.until(ExpectedConditions.elementToBeClickable(By.id("idYes"))).click(); // will explicitly wait for the element to be clickable, else throw timeout exception
}catch(TimeoutException toe){
System.out.println("Check box not present, hence skipping. " + toe); // here you can log or sysout the reason for skipping accompanied with exception
}