Categories

1 Answer

Aug 22, 2019

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);

 }

}

Click here to read more about Selenium
Click here to read more about Insurance

Related questions

Madanswer
Aug 22, 2019 in Selenium
Aug 22, 2019 in Selenium
Aug 22, 2019 in Selenium
...