user5653362 user5653362 - 1 year ago 119
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
Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download