0

I try to select checkbox via chrome webdriver, but always get error like "Element is not clickable at point (x, y)". I use the latest ChromeDriver 2.35. Thanks for help!

Here are the calls I have tried"

driver.findElement(By.xpath("/html[@class='ng-scope']/body[@class='layout-default']/main[@class='container']/form[@class='form-horizontal ng-pristine ng-valid ng-valid-required']/div[@class='row ng-scope']/div[@class='col-md-7']/div[@class='panel panel-default ng-scope']/div[@class='panel-body'][1]/div[@class='list-permission'][1]/div[@class='checkbox'][1]/label")).click();

OR

driver.findElement(By.cssSelector("input[value='platform:AccessWebsite']")).click();

OR

driver.findElement(By.xpath("//input[@value='platform:AccessWebsite']")).click;

Here is the snippet of html source

  <h2>Main Platform</h2>
   <div class="list-permission">
   <div class="checkbox">
   <label>
    <input name="Policy[0][Action][]" type="checkbox" value="platform:AccessWebsite">
    Access to the website
   </label>
  </div>
    .......
    
STONE
  • 3
  • 1
  • 4

1 Answers1

3

When the element is not in a visual portion of the screen, then we will get element not clickable exception. The solution for this is moving the cursor to that element or scrolling the screen.You can use Actions class to move to that element or javascript executor for scrolling. try the below code and let me know.

WebElement element=driver.findElement(By.xpath("/html[@class='ng-scope']/body[@class='layout-default']/main[@class='container']/form[@class='form-horizontal ng-pristine ng-valid ng-valid-required']/div[@class='row ng-scope']/div[@class='col-md-7']/div[@class='panel panel-default ng-scope']/div[@class='panel-body'][1]/div[@class='list-permission'][1]/div[@class='checkbox'][1]/label"));
Actions act= new Actions(driver);
act.moveToElement(element).click().build().perform();

This should work as expected. Note: some browsers may not support actions class, in such case i suggest you to scroll the screen and perform click.

Auro Sarma
  • 441
  • 2
  • 12
  • 1
    I tried this method. The error is disappeared, But the checkbox is not selected. – STONE Feb 22 '18 at 21:31
  • After I use jse.executeScript("scroll(0, -250);") to scroll up the screen. It works with your solution. Thanks! – STONE Feb 22 '18 at 22:21