I'm using selenium on Python and I am converting the result of
name = browser.find_element_by_css_selector('elementname')
to string. It is returning 'WebElement' and what I am doing to convert it is
fname = type(name).__name__
I need it to return the actual element, in which case, it'd be a username of whoever's profile 'browser' is. I just don't know why I am returned 'WebElement'.
Thanks!
(I'm sure I don't need to provide the URL and element name, right?)
find_element_by_css_selector() method returns a WebElement instance. Instead, you need the value of the .text property:
name = browser.find_element_by_css_selector('elementname')
print(name.text)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With