Styrow.dev
Question 41 of 82

How do we get Text of any WebElement?

Question

How do we get Text of any WebElement?

Answer

We can get Text of any WebElement by using getText() method. Below is the code

WebDriver driver = new ChromeDriver();

driver.get(""https://www.google.com"");

String myText = driver.findElement(By.xpath(""xpathToBeGiven"")).getText();

System.out.println(""Text is :""+myText);


šŸ“² Practice Offline on Mobile: Download the free QA Automation & SDET Prep app on Google Play & App Store.