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++;
    }
   
       
    }
       
   
    }

4 comments:

  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
  2. It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me...
    Devops Training in Bangalore
    Best Devops Training in pune

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. You’ve written a really great article here. Your writing style makes this material easy to understand.. I agree with some of the many points you have made. Thank you for this is real thought-provoking content
    Data science course in bangalore

    ReplyDelete