3

I used 3 different waits purposely to locate the element (a checkbox) on the page as shown below and they get passed. After that I click on that same element which also gets passed.

enter image description here

Now my question is if the click element method gets passed then why does Checkbox should be selected fails because in click element method I am clicking on that checkbox only!!

enter image description here

HTML screenshot.

enter image description here

I have tried this clicking on checkbox multiple times using various strategies but it fails every time. Please help and suggest some solution!!

Code I wrote:

`  sleep  2
  wait until page contains element  id_service_levels_0
  wait until element is enabled  id=id_service_levels_0
  wait until element is enabled  id=id_service_levels_0
  page should contain element  id=id_service_levels_0


  click element  id=id_service_levels_0
  checkbox should be selected  id=id_service_levels_0

`

Sammy
  • 77
  • 2
  • 9
  • Have you tried `Select Checkbox id=id_service_levels_0` or alternatively `${element} Get Webelement id=id_service_levels_0` and then `Click Element ${element}`? – A. Kootstra Jun 12 '17 at 19:18

1 Answers1

1

You can try with JavaScript executor as given below.

JavascriptExecutor js = (JavascriptExecutor) driver; js.executeScript("document.getElementById('id_service_levels_0').click()");

Murthi
  • 5,299
  • 1
  • 10
  • 15
  • Can you please let me know how to write it exactly , because writing the command as you said is giving an error (https://www.dropbox.com/s/dulbrjqdncvpf0v/Screenshot%202017-06-12%2023.21.53.png?dl=0). and using command `Execute Javascript document.getElementsById('id_service_levels_0').click()` is giving error `WebDriverException: Message: unknown error: document.getElementsById is not a function` – Sammy Jun 12 '17 at 17:52
  • I have updated the answer. Please try again and let me know. It is not getElementsById and it is getElementById.--singular – Murthi Jun 12 '17 at 17:54
  • That solved thanks, though How can I know when to use Javascript or when to use other functions? – Sammy Jun 12 '17 at 18:15
  • Some webpage, mostly the check boxes elements. You can't directly interact with them. Then you try with JavaScript other elements you can go with out JavaScript. – Murthi Jun 12 '17 at 18:30