How to get the text from label/paragraph in Selenium Java

asked 1 year ago

To verify the expected text is present in the label/paragraph the text needs to be retrieved to compare with the actual text.

getText() method is used to get the text of the element.

Navigate to https://www.qafeast.com/demo,click the Label menu.

Press F12 on the keyboard and inspect the Label.

getText_selenium Java

Syntax:

driver.findElement(By.

Example: 

WebElement label=driver.findElement(By.xpath("//h3[text()='Test automation']"));
System.out.println(label.getText());

Output: Test automation