Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Choose XPATH based on <th> string value with selenium

There is a table that I want to get the XPATH of, however the amount of rows and columns is inconsistent across results so I can’t just right click and get copy the full XPATH.

My current code:

result_priority_number = driver.find_element(By.XPATH, "/html/body/div/div[2]/div[6]/div/div[2]/table/tbody/tr[18]/td[2]")

The table header names though are always consistent. How do I get the value of an element where the table header specifically says something (i.e. "Priority Number")

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

I can’t just right click and get copy the full XPATH.

Never use this method. Xpath has a very useful feature for search! It isn’t just for nested pathing!


//td[contains(text(),'header value')]

or if it has many tables and you want only one of its:


//table[@id='id_of_table']//td[contains(text(),'header value')]

or the table hasn’t id or class:


//table[2]//td[contains(text(),'header value')]

where 2 is index of table in page

and other many feature for searching in html nodes

in your case, for get Filing language:

//td[contains(text(),'Filing language')]/following-sibling::td
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading