如何使用Selenium和Java查找并单击select boolean复选框
我正在尝试使用id单击primefaces select boolean复选框,但无法单击。我遇到一些异常,原因是:如何使用Selenium和Java查找并单击select boolean复选框,java,selenium,selenium-webdriver,xpath,css-selectors,Java,Selenium,Selenium Webdriver,Xpath,Css Selectors,我正在尝试使用id单击primefaces select boolean复选框,但无法单击。我遇到一些异常,原因是: org.openqa.selenium.NoSuchElementException: Cannot locate an element using By.id: runDARtest1 我也增加了第二个30秒,但同样的问题再次出现 driver.get("http://localhost:5080/MOIA2-WEB/"); driver.findElement(By.id(
org.openqa.selenium.NoSuchElementException: Cannot locate an element using By.id: runDARtest1
我也增加了第二个30秒,但同样的问题再次出现
driver.get("http://localhost:5080/MOIA2-WEB/");
driver.findElement(By.id("moia2Form:loginForm:tabViedID:userName")).sendKeys("cherie.chen");
driver.findElement(By.id("moia2Form:loginForm:tabViedID:password")).sendKeys("Password1");
driver.findElement(By.id("moia2Form:loginForm:tabViedID:loginButton")).click();
driver.findElement(By.id("moia2Form:lnkMarketClearing")).click();
driver.findElement(By.id("moia2Form:system_Result_runinfo")).click();
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.elementToBeClickable(By.id("runDARtest1"))).click();;
Xhtml代码:选中表格中的布尔复选框
<tr>
<td><label class="switch"> <h:selectBooleanCheckbox
class="runDARclass"
value="#{systemResultManagedBean.runDAR}" id="runDAR" />
<span class="slider round" id="runDARtest1"></span>
</label></td>
<td><p:spacer width="5px" /><span>DAR</span></td>
</tr>
达尔
所需的元素是一个动态元素,因此要在元素上单击(),您必须引导WebDriverWait使元素可单击,并且您可以使用以下任一解决方案:
:css选择器
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("label.switch span.slider.round#runDARtest1"))).click();
:xpath
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//label[@class='switch']//span[@class='slider round' and @id='runDARtest1']"))).click();
:css选择器
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("label.switch span.slider.round#runDARtest1"))).click();
:xpath
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//label[@class='switch']//span[@class='slider round' and @id='runDARtest1']"))).click();
添加到错误跟踪日志中。由于错误堆栈跟踪中的错误消息被字包装,因此调试变得很困难。我会小心的…-)@Kamal我们如何说服您不要将
添加到错误跟踪日志中。由于错误堆栈跟踪中的错误消息被字包装,因此调试变得很困难。我会小心的…-)我添加了上面提到的两个代码,但仍然遇到以下异常:无法使用By.xpath://label[@class='switch']//span[@class='slider round'和@id='runDARtest1']@RameshKumar找到元素cssSelector
?如何获得相同的结果exception@RameshKumar你能从答案中复制并粘贴我的代码吗。我提供的答案永远不会引发异常:找不到元素,而是它可以引发TimeoutException.new WebDriverWait(driver,20).until(ExpectedConditions.elementToBeClickable(By.xpath(//label[@class='switch']//span[@class='slider round'和@id='runDARtest1'])。单击();我添加了上面提到的两个代码,但仍然遇到以下异常:无法使用By.xpath://label[@class='switch']//span[@class='slider round'和@id='runDARtest1']@RameshKumar找到元素cssSelector
?如何获得相同的结果exception@RameshKumar你能从答案中复制并粘贴我的代码吗。我提供的答案永远不会引发异常:找不到元素,而是它可以引发TimeoutException.new WebDriverWait(driver,20).until(ExpectedConditions.elementToBeClickable(By.xpath(//label[@class='switch']//span[@class='slider round'和@id='runDARtest1'])。单击();