Selenium WebDriver Java - Clicking on element by label not working on certain labels -


i trying click on element label. here code using:

driver.findelement(by.xpath("id(//label[text() = 'label text here']/@for)")).click(); 

it works (select all) & hayward cant find los angeles, san fran, or san jose.

update:

for guess may best option until see better. allow user pass full string , function in method grab last word of string , insert contains xpath.

public void substringlocationtest(string location) {      string par = location.substring(location.lastindexof(" ") + 1);      driver.findelement(by.xpath("//label[contains(text(), '" + par + "')]")).click();  } 

here html code:

<div id="reportviewer1_ctl04_ctl03_divdropdown" onclick="event.cancelbubble=true;" onactivate="event.cancelbubble=true;" style="border: 1px solid rgb(169, 169, 169); font-family: verdana; font-size: 8pt; overflow: auto; background-color: window; display: inline; position: absolute; z-index: 11; left: 131px; top: 41px; width: 188px;">     <span><table cellpadding="0" cellspacing="0" style="background-color:window;">         <tbody><tr>             <td nowrap="nowrap"><span style="font-family:verdana;font-size:8pt;"><input id="reportviewer1_ctl04_ctl03_divdropdown_ctl00" type="checkbox" name="reportviewer1$ctl04$ctl03$divdropdown$ctl00" onclick="$get('reportviewer1_ctl04_ctl03').control.onselectallclick(this);"><label for="reportviewer1_ctl04_ctl03_divdropdown_ctl00">(select all)</label></span></td>         </tr><tr>             <td nowrap="nowrap"><span style="font-family:verdana;font-size:8pt;"><input id="reportviewer1_ctl04_ctl03_divdropdown_ctl02" type="checkbox" name="reportviewer1$ctl04$ctl03$divdropdown$ctl02" onclick="$get('reportviewer1_ctl04_ctl03').control.onvalidvalueclick(this, 'reportviewer1_ctl04_ctl03_divdropdown_ctl00');"><label for="reportviewer1_ctl04_ctl03_divdropdown_ctl02">hayward</label></span></td>         </tr><tr>             <td nowrap="nowrap"><span style="font-family:verdana;font-size:8pt;"><input id="reportviewer1_ctl04_ctl03_divdropdown_ctl03" type="checkbox" name="reportviewer1$ctl04$ctl03$divdropdown$ctl03" onclick="$get('reportviewer1_ctl04_ctl03').control.onvalidvalueclick(this, 'reportviewer1_ctl04_ctl03_divdropdown_ctl00');"><label for="reportviewer1_ctl04_ctl03_divdropdown_ctl03">los angeles</label></span></td>         </tr><tr>             <td nowrap="nowrap"><span style="font-family:verdana;font-size:8pt;"><input id="reportviewer1_ctl04_ctl03_divdropdown_ctl04" type="checkbox" name="reportviewer1$ctl04$ctl03$divdropdown$ctl04" onclick="$get('reportviewer1_ctl04_ctl03').control.onvalidvalueclick(this, 'reportviewer1_ctl04_ctl03_divdropdown_ctl00');"><label for="reportviewer1_ctl04_ctl03_divdropdown_ctl04">san francisco</label></span></td>         </tr><tr>             <td nowrap="nowrap"><span style="font-family:verdana;font-size:8pt;"><input id="reportviewer1_ctl04_ctl03_divdropdown_ctl05" type="checkbox" name="reportviewer1$ctl04$ctl03$divdropdown$ctl05" onclick="$get('reportviewer1_ctl04_ctl03').control.onvalidvalueclick(this, 'reportviewer1_ctl04_ctl03_divdropdown_ctl00');"><label for="reportviewer1_ctl04_ctl03_divdropdown_ctl05">san jose</label></span></td>         </tr>     </tbody></table><input type="hidden" name="reportviewer1$ctl04$ctl03$divdropdown$ctl01$hiddenindices" id="reportviewer1_ctl04_ctl03_divdropdown_ctl01_hiddenindices" value=""></span> </div> 

you can use xpath locater. example:

d.findelement(by.xpath("//...../label[contains(@for,'reportviewer1_ctl04_ctl03_divdropdown_ctl02')]")).click(); 

Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -