0

I have created below XPath but it is not working as expected.

I am checking text in the cell of a html table and I want a particular cell to be matched.

I have created below XPath but it is not working.

*//table[@id="customerPortalTable"]//tbody//tr[td[ contains(translate(text(), "abcdefghijklmnopqrstuvwxyz", "ABCDEFGHIJKLMNOPQRSTUVWXYZ"), "{0}") ]]

{0} - This is the place holder for value to search

I want to match below values

Test Account or TEST ACCOUNT or Test ACCOUNT

<td class="left filterInputColumn">Test Account</td>
<td class="left filterInputColumn">Test ACCOUNT</td>
<td class="left filterInputColumn">TEST ACCOUNT</td>
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Nitin Rathod
  • 159
  • 2
  • 15
  • 1
    an example of what you are attempting to match and what value you are providing would be helpful. For instance, are you searching with an UPPER-CASE value? Does your HTML have a table with that `@id`? Does the table have `tdbody`? All questions that we have no answers to. – Mads Hansen Apr 07 '22 at 14:49
  • It does have table with that ID. I want to match this - Test Account as well as TEST ACCOUNT. I want do match not case sensitive – Nitin Rathod Apr 07 '22 at 19:09

2 Answers2

0

To create the case insensitive you can use the following solution:

"//table[@id="customerPortalTable"]//tbody//tr[.//td[contains(translate(., 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), '{}')]]".format(placeholder)

Effectively, your line of code will be:

placeholder= "Test Account"
WebElement element = driver.findElement(By.xpath("//table[@id="customerPortalTable"]//tbody//tr[.//td[contains(translate(., 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), '{}')]]".format(placeholder)));

References

You can find a couple of relevant detailed discussions in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

Generally your XPath looks ok to me. Maybe the issue is connected with whether you search uppercase or lowercase, for example these both are returning the three td nodes:

 //td[contains(translate(text(), 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'), 'TEST ACCOUNT')]
 
 //td[contains(translate(text(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), 'test account')]
K. B.
  • 3,342
  • 3
  • 19
  • 32