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
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It only takes a minute to sign up.
Sign up to join this communityYour 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')]")
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.
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.
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();
.//*[contains(@id,'text-center') and contains(text(), 'xlsx')]
//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.