Reputation: 311
I am try to grab data from a table that has two columns. The rows do not have a distinct identifier. But I can search the first column for specifics to find out if I should grab the second column's data. The table does not have an id, but the Div does. I need to grab the dollar amounts seen in the screen shot below. I would be very grateful for your help.
Upvotes: 0
Views: 210
Reputation: 23825
You should try using By.xpath()
with preceding-sibling
axis as below :-
To get Estimated tax to be collected:
driver.FindElement(By.xpath(".//td[preceding-sibling::td[text() = 'Estimated tax to be collected:']]")).Text
To get Total:
driver.FindElement(By.xpath(".//td[preceding-sibling::td[text() = 'Total:']]")).Text
Upvotes: 0
Reputation: 532
I suggest installing the firefox plugin firepath and get the xpath in this way
Upvotes: 0
Reputation: 9058
Use following-sibling in xpath
//div[@id='subtotals-marketplace-table']//td[contains(text(),"Estimated tax")]/following-sibling::td[1]
//div[@id='subtotals-marketplace-table']//td[contains(text(),"Total")]/following-sibling::td[1]
Upvotes: 1