getText() Method

getText method will be used to get the String value of the web element such as button, link, etc.,
User need to provide the input to locate the element such as id, class, classname, xpath, css Selector, linktext, partiallinktext.  It will return the string value of the web element or the component.

JAVA API Syntax : java.lang.String getText()

Code:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.chrome.*;

public class gtSize {
 
private static WebDriver driver = null;
 
public static void main(String[] args){

//setting the property for chrome browser and to invoke the chrome browser
System.setProperty("webdriver.chrome.driver", 
"C://Selenium//chromedriver.exe");  

WebDriver driver=new ChromeDriver();

driver.get("http://www.bing.com");

//Retrieving the text from the logo of www.Bing.com
WebElement Blogo = driver.findElement(By.id("sbox"));

//Printing the result into the console using getText method for Bing logo
System.out.println(Blogo.getText());

}
}
Output
Starting ChromeDriver (vx.x.241075) on port 45554
Bing
Socialize It and Share the post with your friends
SOCIALIZE IT →
FOLLOW US →
SHARE IT →