I am testing a webpage where I need to select a couple of checkboxes and then click submit.
My problem is that which ever checkbox I ask Selenium to click on first is ignored. No matter what order I put them in, the first one it comes to in the code won't be clicked, but conversely the test won't fail, so I know Selenium has at least located it, and thinks it's clicked on it.
I started with this:
driver.findElement(By.id("g1:1")).click();
driver.findElement(By.id("g2:1")).click();
Each time the second element was clicked but not the first. I then added a WebDriverWait before it, in case it was something to do with that, like so:
WebDriverWait wait = new WebDriverWait(driver, 5);
wait.until(ExpectedConditions.elementToBeClickable(driver.findElement(By.id("g1:1"))));
driver.findElement(By.id("g1:1")).click();
driver.findElement(By.id("g2:1")).click();
Which had the same problem. I then also tried wrapping them in an 'if' statement to check for the Element's status first, then click it if it's not selected:
WebDriverWait wait = new WebDriverWait(driver, 5);
wait.until(ExpectedConditions.elementToBeClickable(driver.findElement(By.id("g1:1"))));
if ( !driver.findElement(By.id("g1:1")).isSelected() ) {
driver.findElement(By.id("g1:1")).click();
}
if ( !driver.findElement(By.id("g2:1")).isSelected() ) {
driver.findElement(By.id("g2:1")).click();
}
None of these things has helped. If I comment out the first checkbox the problem then simple moves to the second one.
Any ideas of what I'm missing?
Aucun commentaire:
Enregistrer un commentaire