enter image description here

I need to find the xpath for the line in the image with highlighted text. The highlighted text/number is dynamic. Once I find the xpath, I can save it in a variable using getText().

Kindly help me. I am kind a stuck on it for a while

6 Answers 6


Your text is dynamic, but it always contains .xlsx. So you can find the element with partial text matching.

Try this:


Or more specifically:

By.xpath("//td[@id = 'noOfSites_row1 text-center' and contains(text(), 'xlsx')]")
  • Yeah that one works too, but only when I want to get xpath for first element with xlsx. Thanks Commented Feb 16, 2018 at 8:39
  • 2
    One suggestion. Always try to use relative xpath instead of absolute xpath.
    – Shahid
    Commented Feb 16, 2018 at 8:44

Try this-

Inspect the webpage and press ctrl + F. Then in the search bar paste the above command and search how many web elements gets matches. If multiple elements matches then pass the number where it is occurred.


Your xpath would be


Since according to your question you need the very first line and the second column of the table. You there are more specific criteria you can describe them in the comments to my answer.


The simple way is //table[@id='fileUploadTable']/tbody/tr[1]/td[3] but you can use more smarter way something like this: //table[@id='fileUploadTable']/tbody/tr[td = "*.xlsx"] Please check it. It should work. You can find additional info by the link Xpath


This should definitely works.

WebDriver driver=null;
driver.findElement(By.xpath("//table[@id = 'fileUploadTable']/tbody/tr[1]/td[3]/a")).click();
  • Hi Shadab, can you explain why it should work?
    – dvniel
    Commented Dec 19, 2018 at 13:18
  • XPath is used to find the location of any element on a webpage using XML path expression. So firstly we need to traverse to that particular location then call click function. What actually Alexey missed in his answer was /a. Commented Dec 19, 2018 at 13:27
  1. .//*[contains(@id,'text-center') and contains(text(), 'xlsx')]

  2. //tbody//tr//td:nth-child(3)

Give me HTML I will give you more if required. Don't use any tool which gives you a ready made xpath. Try to write on your own so you better understand how xpath works.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.