1

I need to extract text Paul Robert this html and print to the console using the Java WebDriver and selenium .

The code below extracts all text Div , even the text " Quit".

<div role="alert" class="alert success" id="control_gen_3">
 <p>
 <strong>Invite to <a href="">Paul Robert</a>.</strong></p>
 <button class="dismiss" id="global-error-dismiss">Quit</button>
 </div>

Code Selenium:

String pessoa = driver.findElement(By.id("control_gen_3")).getText();               
System.out.println(pessoa );

2 Answers 2

2
String pessoa = driver.findElement(By.xpath("//div[@id='control_gen_3']//a")).getText();               
System.out.println(pessoa );

Hope this helps you..

Sign up to request clarification or add additional context in comments.

Comments

1
String pessoa = driver.findElement(By.cssSelector("#control_gen_3 a")).getText();               
System.out.println(pessoa);

This means you fetch the element with id control_gen_3 and look for an a within that element.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.