hey, you can use get.text() method to get the string from the particular section of the website.
Here is the program that I used and it worked pretty well.
System.setProperty("webdriver.chrome.driver","C:\\Users\\priyj_kumar\\Downloads\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://en.wikipedia.org/wiki/Main_Page");
String str = driver.findElement(By.xpath("//*[@id='mp-tfa']/p")).getText();
System.out.println(str);
This way you can get the string from the website.
Hope this helps!
Check out our Selenium Course led by industry experts to learn more!
Thanks!