Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Selenium element.text() is not considered as a string

Im trying to get an element name with python selenium and print it later but it throws following error:

selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: 'using' must be a string

Code line looks like this:

title = driver.find_element((By.CLASS_NAME, 'mt-3')).text()

HTML element looks like this:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<h1 class="mt-3">ElementTitle</h1>

I tried searcing for element by XPath but it seems not to be a reason for error…

>Solution :

To get a web element text you should apply .text on it, not .text()
Also, there are unnecessary parenthesis here that should be removed.
So, instead of

title = driver.find_element((By.CLASS_NAME, 'mt-3')).text()

it should be

title = driver.find_element(By.CLASS_NAME, 'mt-3').text
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading