0

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

2

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

Try this:

By.xpath("//td[contains(text(),'xlsx')]")

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 – ashish shahu Feb 16 '18 at 8:39
  • 2
    One suggestion. Always try to use relative xpath instead of absolute xpath. – Shahid Feb 16 '18 at 8:44
1

Try this-
By.xpath("//td[contains(text(),'xlsx')]").

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.

0

Your xpath would be

//table[@id='fileUploadTable']/tbody/tr[1]/td[3]

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.

0

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

0

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? – trashpanda Dec 19 '18 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. – Shadab Akhtar Dec 19 '18 at 13:27
0
  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, privacy policy and cookie policy

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