1.

What is the best way to acquire the textual matter of a web element?

Answer»

The best WAY to acquire the textual matter of a web element is by employing the getText() method as shown below:

PACKAGE interviewBit;// package nameimport org.openqa.selenium.By;import org.testng.annotations.TEST;import org.openqa.selenium.chrome.ChromeDriver;import org.openqa.selenium.WebDriver;// importing the necessary libraries// Test classpublic class Test {@Testpublic void testmethod(){// sets the property as requiredSystem.setProperty("webdriver.chrome.driver","C:\\Selenium Environment\\Drivers\\chromedriver.exe");//Creates a new Chrome Web DriverWebDriver driver = new ChromeDriver();driver.get("HTTPS://www.youtube.com");STRING textAvailable=driver.findElement(By.xpath("//*[@id='gbw']/div/div/div[1]/div[1]/a")).getText(); System.out.println("Textual Matter which is Present is :" + textAvailable);}}


Discussion

No Comment Found