Is there any way to get the text of a web element using Selenium Webdriver?

0 votes
May 29 in Selenium by Komal
265 views

1 answer to this question.

0 votes

Hey Komal, to get the text of a web element in Selenium Webdriver you can use getText() method:

package getTextPackage;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;
public class getTextTest {

 @Test
 public void testmethod(){
  System.setProperty("webdriver.chrome.driver", "C:\\Downloads\\Drivers\\chromedriver.exe");
    WebDriver driver = new ChromeDriver();
    driver.get("https://www.google.com");
    String availableText = driver.findElement(By.xpath("//*[@id='gbw']/div/div/div[1]/div[1]/a")).getText();
    System.out.println("Text Available is :"+availableText);
 }
}
answered May 29 by Anvi
• 13,960 points

Related Questions In Selenium

0 votes
1 answer
0 votes
1 answer

Is it possible to manually set the attribute value of a Web Element using Selenium?

Yes, its very much possible. You just ...READ MORE

answered May 8, 2018 in Selenium by king_kenny
• 3,650 points
7,078 views
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,110 points
1,007 views
0 votes
1 answer
0 votes
1 answer

What is the role of TestNG & JUnit frameworks in Selenium?

Well TestNG and JUnit are test frameworks ...READ MORE

answered Apr 18, 2018 in Selenium by king_kenny
• 3,650 points
343 views
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,130 points
1,153 views
0 votes
1 answer
0 votes
1 answer