Hi I am trying to get the word count in a paragraph. The following is my code to find the count. Kindly check the code and tell me the mistake.
Code
----
package checking;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.RemoteWebDriver;
public class WordCount {
public static void main(String[] args) {
RemoteWebDriver driver;
//driver = new FirefoxDriver();
System.setProperty("webdriver.chrome.driver", "./drivers/chromedriver.exe");
driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("https://jqueryui.com/");
WebElement Para = driver.findElement(By.xpath("//*[@id='banner-secondary']/p"));
String ParaCon = Para.getText();
System.out.println("Paragraph Content : "+ParaCon);
int ParaConCount = ParaCon.length();
System.out.println("Paragraph Characters Count : "+ParaConCount);
int count=0;
for (int i = 0; i <= ParaConCount; i++) {
if (ParaCon.contains("of")) {
count++;
break;
}
}
System.out.println("Count of Word present : "+count);
driver.quit();
}
}
It should get thecount of thw word whatiam giving