Sebastian Nielsen Sebastian Nielsen - 24 days ago 7
Python Question

python selenium - how to read/store a text on a webpage

https://gyazo.com/6f590c16fc078a0cd90fa2b0d4343d3c
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

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