I'm trying to get text using Selenium WebDriver and here is my code. Please note that I don't want to use XPath, because in my case the ID gets changed on every relaunch of the web page.
My code:
text = driver.find_element_by_class_name("current-stage").getText("my text")
HTML:
<span class="current-text" id="yui_3_7_0_4_1389185744113_384">my text</span>
How can I fix this?
getText() Method in Selenium This method helps retrieve the text, which is basically the innertext of a WebElement. getText() method returns string as a result. It removes the whitespaces if present in the front and back of the string.
Selenium offers a getText() method used to get the text of an element, i.e.; it can be used to read text values of an element from a web page.
You want just .text
.
You can then verify it after you've got it, don't attempt to pass in what you expect it should have.
Python
element.text
Java
element.getText()
C#
element.Text
Ruby
element.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