Sebastian Nielsen Sebastian Nielsen - 4 months ago 25
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?


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