0

I want to find the element for a checkbox on the page:

this is the source code of the page:

<tr>
                        <td class="tablecell"  width="200" valign="top">Filter_list</td>
                        <td class="tablecell"  width="360">
                            <div id="div_filterlist">
                                <table border="0">
                                    <tr>
                                        <td class="tablecell"  width="160" valign="top"><b>Available Filters</b><br>
                                            <ul id="unselected_ilters" class="unselected_filter">

                                                <li itemID="test">
                                                    <input type="checkbox" value="test" onClick="toggleUnselected(this,'test')" onMouseOver="this.style.cursor='hand'"/>&nbsp;&nbsp;&nbsp;
                                                    <a href="#" onClick="document.filterform.name.value='test';document.filterform.submit();">test</a>
                                                </li>

My code is not working:

String xpathLocater = "//input[ @type=\"checkbox\" and @value=\" test\"]"; 
3
  • in which way your code is not working? any exception? Commented Dec 14, 2015 at 18:33
  • are you able to edit the HTML of the page? Commented Dec 14, 2015 at 18:37
  • I got "Unable to locate element:" Commented Dec 14, 2015 at 18:56

1 Answer 1

1

css selector:
String cssLocator = "input[type=checkbox]"; or
String cssLocator = "input[type=checkbox][value=test]";

xpath selector:
String xpathLocator = "//input[@type=\"checkbox\"]"; or
String xpathLocator = "//input[@type=\"checkbox\" and @value=\"test\"]";

If you still can't find the element check 2 things:

  • whether that element inside iframe: if yes - you need to switch to iframe first
  • add wait before finding an element (you could try to find element before it was added to DOM)
Sign up to request clarification or add additional context in comments.

7 Comments

not working String xpathLocater = "//input[ @type=\"checkbox\" and @value=\" test\"]";
it should. can you share the link to web page or give more html snippet?
Unable to locate element: {"method":"xpath","selector":"//input[@type=\"checkbox\" and @value=\"NewAlarm\"]"}
this sis the xpath link to the element: html/body/form[1]/table/tbody/tr/td/table/tbody/tr[6]/td[2]/div/table/tbody/tr/td[1]/ul/li[1]/input
two form in one page, <form name="alarmform" action="viewalarmdef.jsp" method="post">
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.