user5653362 user5653362 - 8 months ago 75
Python Question

Unable to locate xpath

Here is my HTML code:

enter image description here

I want to go to the tr where the label is CompanyId and get the td text which is 512571(last line). How can I achive this?

Here is what I tried:

driver.find_element_by_xpath('//label[contains(text(), "CompanyId")]').text

Sai Sai

The following xpath should work:


Relevant line of code:


Note: by default the xpath will select the first occurrence of a td - in this case CompanyId looks like a label that is immediately followed by the data you are looking for. You could always use an index of you always want the first td