Reputation: 3120
So I'm running into the issue where I need 90% of the time
//*[@id='MainContent']/tbody/tr[18]/td[2]
while I need 10% of the time
//*[@id='MainContent']/tbody/tr[20]/td[2]
I'm wondering what the best approach to compensate for this change would be.
Here are pictures of the table, and the html code to the table.
I need to capture the 3 Bedrooms
part, and there are times where the tr
elements swap. Most of the time the first xpath code works, but I need a more efficient way of determining which xpath to use depending on the case at hand.
I know that a starts-with method exists for selenium, but would that allow me to search the actual TD text?
Upvotes: 1
Views: 799
Reputation: 193308
To capture the text 3 Bedrooms with respect to the text Ttl Bedrms you can use the following solution:
XPath
:
//tr[@class='RowStyle']//td[contains(.,'Ttl Bedrms')]//following::td[1]
Upvotes: 3
Reputation: 50939
How about using the Ttl Bedrms:
text
//*[@id='MainContent']//td[contains(., `Ttl Bedrms:`)]/following-sibling::td
Upvotes: 2