Friday, 27 December 2013

Selenium Webdriver - Count Words of Paragraph -Example

public static void main(String[] args)
{

      WebDriver driver = new FirefoxDriver();
      driver.navigate().to("http://www.tizag.com/htmlT/htmlparagraphs.php");
       String text;
       int len;
       int i;
   
     text= driver.findElement(By.xpath("/html/body/table[3]/tbody/tr/td[2]/table/tbody/tr/td/div[4]/p")).getText().toString();
      len=text.length();
 
      int counter=0;
      for (i=0;i<=len-1;i++)
      {
   
     if(Character.isLetter(text.charAt(i)))
     {
     counter++;
     for(;i<=len-1;i++)
     {
     if(text.charAt(i)==' '){
     counter++;
                      }
              }
     }
     }
     System.out.print(counter);
     System.out.print("\n");

//For Counting Duplicate words
     int len2=counter/((int)2);
     text=text.trim();
     String[] words = text.split(" ");
     int counter1=0;
    for(i=0;i<=len2;i++)
    {
   
   
    for(int j=0;j<=len2;j++)
    {
    if(words[i]==words[j])
    {
    System.out.print(words[i]);
    System.out.print("---");
    System.out.print(words[j]);
        System.out.println();
    counter1++;
    }
   
       
    }
       
   
    }

1 comment:

  1. Programming was very easily understand and more important coding are provided on this post and this is very valuable in my studies,all coding easily understand and develop more skills,thanks for sharing this post.
    informatica

    ReplyDelete