Sebastian Nielsen Sebastian Nielsen - 1 year ago 95
Python Question

python selenium - how to read/store a text on a webpage
As you can see I want my script to read that text "29 dage"
But how do I locate that with selenium. I can see that it is under

class="dbaListing listing lastListing"
and its the 4th
I want python to read. How do I do that?

Answer Source

Selenium provides a function find_element_by_css_selector() which locates the first element based on the provided CSS selector. (There's a multi-item variant, find_elements_by_css_selector(), that returns a list of all matching elements.)

text = driver.find_element_by_css_selector('.dbaListing.listing.lastListing > td:nth-child(4) > span').text
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download