How to get text with Selenium WebDriver in Python

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?


Solution 1:

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.

Solution 2:

Python

element.text

Java

element.getText()

C#

element.Text

Ruby

element.text