1

I'm trying to get my checkbox clicked while running using selenium.

I have no issue running my test when using chromedriver. But when I switch to HtmlUnitDriver, it will throw error when it reaches the clicking of checkbox action. The error thrown is

org.openga.selenium.ElementNotVisibleException: You may only interact with visible elements

I've tried multiple methods like:

driver.findElement(By.xpath("//*[@id=\"chkConfirm\"]")).sendKeys(Keys.SPACE);
driver.findElement(By.xpath("//*[@id=\"chkConfirm\"]")).click();

But none of it works. Can someone help me out?

Rao
  • 20,781
  • 11
  • 57
  • 77
JustStarted
  • 199
  • 4
  • 13

3 Answers3

0
WebElement checkBox = driver.findElement(By.xpath("//*[@id='chkConfirm']"))
checkBox.isDisplayed();
if(!checkBox.isSelected())
checkBox.click();

Try this block.

piet.t
  • 11,718
  • 21
  • 43
  • 52
Sudha Velan
  • 633
  • 8
  • 24
0

Could you add wait before clicking on the element? See an example below.

WebDriverWait wait = new WebDriverWait(driver, 20);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@id=\"chkConfirm\"]")));
driver.findElement(By.xpath("//*[@id=\"chkConfirm\"]")).click();
Buaban
  • 5,029
  • 1
  • 17
  • 33
0

Okay. I've tried both the suggested answer but none works.

So I decided to move on to PhantomJS and it works.

PhantomJS

Thanks everyone!

JustStarted
  • 199
  • 4
  • 13