Im trying to get an element name with python selenium and print it later but it throws following error:
JavaScript
x
2
1
selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: 'using' must be a string
2
Code line looks like this:
JavaScript
1
2
1
title = driver.find_element((By.CLASS_NAME, 'mt-3')).text()
2
HTML element looks like this:
JavaScript
1
2
1
<h1 class="mt-3">ElementTitle</h1>
2
I tried searcing for element by XPath but it seems not to be a reason for error…
Advertisement
Answer
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
JavaScript
1
2
1
title = driver.find_element((By.CLASS_NAME, 'mt-3')).text()
2
it should be
JavaScript
1
2
1
title = driver.find_element(By.CLASS_NAME, 'mt-3').text
2