How to get the text of a span?

0

For example, in this line of code I need the "x + 10 = 10". Does anyone know how to do it?

<span class="task" onclick="loadExercise(201)" id="task201">x+10=10</span>
    
asked by anonymous 30.11.2016 / 20:16

3 answers

1

If you are using python for example you can use .text:

name = driver.find_element_by_id("task201").text
print (name)

x+10=10
    
01.12.2016 / 13:49
0

I think that's how it works:

var elemento = browser.FindElement(By.Id("task201")).Text;

or

var elemento = browser.FindElement(By.Id("task201")).GetAttribute("innerText");
    
01.12.2016 / 13:45
0

You first need to identify if the element is dynamic or it is part of a list and every time it appears it may be in a different location, the most common and safe way to capture text is like this:

texto String;

texto = driver.findElemnt(By.xpath(//span [text()='x+10=10'])).text; //desta forma ele vai localizar o texto mesmo que ele mude de posição na pagina  
    
17.07.2017 / 15:11