1 Answer

0 votes
by

By using getText() method

package softwareTestingMaterial;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

import org.testng.annotations.Test;

public class TestTestTest {

@Test

public void testmethod(){

System.setProperty("webdriver.chrome.driver", "D:\\Selenium Environment\\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);

}

}

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

package softwareTestingMaterial;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

import org.testng.annotations.Test;

public class TestTestTest {

 

 @Test

 public void testmethod(){

 System.setProperty("webdriver.chrome.driver", "D:\\Selenium Environment\\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);

 }

}

Related questions

0 votes
asked Aug 22, 2019 in Selenium by john ganales
0 votes
asked Aug 22, 2019 in Selenium by john ganales
...