java - Selenium wont click the first checkbox on the page -


i testing webpage need select couple of checkboxes , click submit.

my problem ever checkbox ask selenium click on first ignored. no matter order put them in, first 1 comes in code won't clicked, conversely test won't fail, know selenium has @ least located it, , thinks it's clicked on it.

here's html of check boxes:

<ul class="input"> <li class="expandable"> <span class="expand-link collapsed" title="click collapse"></span> <input type="checkbox" id="g1:1" name="g1" value="1"> <label for="g1:1">some text</label> <ul class="">  <ul class="input"> <li class="expandable"> <span class="expand-link collapsed" title="click collapse"></span> <input type="checkbox" id="g2:1" name="g2" value="1"> <label for="g2:1">some text</label> <ul class=""> 

i started this:

driver.findelement(by.id("g1:1")).click(); driver.findelement(by.id("g2:1")).click(); 

each time second element clicked not first. added webdriverwait before it, in case that, 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 same problem. tried wrapping them in 'if' statement check element's status first, click 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 comment out first checkbox problem simple moves second one.

any ideas of i'm missing?

html snippet

<li class="expandable">  <span class="expand-link collapsed" title="click collapse"></span>  <input type="checkbox" id="g1:1" name="g1" value="1">      <label for="g1:1">some text</label> </input> 

after hunting around never managed find out why happening, did end work around i'll post sake of passing through.

by using selenium's ability execute specific bits of javascript able check checkbox way. keep in mind haven't removed code above, fail first checkbox, regardless of was. anyway, code added past issue:

    webelement firstcheckbox = driver.findelement(by.id("someid"));                 javascriptexecutor executor = (javascriptexecutor) driver;     executor.executescript("jquery(document.getelementbyid('someid')).prop('checked', true)", firstcheckbox); 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -