Reputation: 639
I'm trying to extract some text from a page using Python and Selenium The text is visible to me, but I can't work out how to extract it - I think the text was created in Java.
Im on the URL: "https://sellercentral.amazon.co.uk/hz/fba/profitabilitycalculator/index?lang=en_GB" and have entered the product id 'B00FRJ1R4M' for example, pressed search, then entered '20' in the Amazon Fulfilment Item Price box and pressed calculate.
I'm trying to extract the '-5.59' but to no avail.
The closest I think I've got is the follwing code:
cost = driver.find_element_by_xpath("//*[@id='afn-fees']/dl/dd[15]/input")
print(cost.get_attribute('innerHTML'))
print(driver.execute_script("return arguments[0].innerHTML", cost))
But this for returns 'None'.
Any help would be much appreciated.
Upvotes: 1
Views: 650
Reputation: 473863
You need to use .get_attribute("value")
, since this is an input
, and simplify your locator:
cost = driver.find_element_by_css_selector("input.cost-total")
print(cost.get_attribute("value"))
Here input.cost-total
CSS selector would match an input
element having cost-total
class, which is quite readable and reliable locator in this case.
Upvotes: 1