0
votes

i am trying to click on 2nd item(Not Know) in the Td element. I was able to click on the 1st item(known Issue) by using its xpath. How ever i am not able to do the same thing with the 2nd option. i am getting following error

Unable to locate an element with the xpath expression
//*[@id='group_tree']/div/div/div/div[1]/div/div[1]/table/tbody/tr/td[[contains(text(), 'Not Known')]
because of the following error:

below is my code:

driver.findElement(By .xpath("//*[@id='group_tree']/div/div/div/div[1]/div/div[1]/table/tbody/tr/td[[contains(text(), 'Not Known')]"));

and my HTML is

<div style="display: block;">
    <div>
        <table cellspacing="0px" cellpadding="0px"
            style="background-color: transparent;">
            <tbody>
                <tr>
                    <td><img class="tree" src="images/s.gifx" alt=""
                        style="margin-left: 16px;"></td>
                    <td class="tree_spacer"><img alt="" src="images/nav_bult.gifx"></td>
                    <td title="" class="tree_item_text"><a
                        name="37fd8721a9729140d11a2c59127b17a6">Known issue</a><span></span></td>
                </tr>
            </tbody>
        </table>
        <div></div>
    </div>
    <div>
        <table cellspacing="0px" cellpadding="0px"
            style="background-color: transparent;">
            <tbody>
                <tr>
                    <td><img class="tree" src="images/s.gifx" alt=""
                        style="margin-left: 16px;"></td>
                    <td class="tree_spacer"><img alt="" src="images/nav_bult.gifx"></td>
                    <td title="" class="tree_item_text"><a
                        name="ea1e8721a9729140d11a2c59127b17fb">Not known</a><span></span></td>
                </tr>
            </tbody>
        </table>
        <div></div>
    </div>
</div>

i tried finding the element by name, by xpath and contains but everything is throwng error

Please Help

1

1 Answers

0
votes

Before doing anything first check if your html is valid, I verified that your html misses matching </img> tags for the existing <img> tags.

Now, I assume you want the td elements with Known issue and Not known as text for a elements.

The following xpaths will give you those :

//td[@class='tree_item_text' and ./a/text()='Known issue']
//td[@class='tree_item_text' and ./a/text()='Not known']