Question

I have a comment page where people can write a comment in text field and post the comment by clicking on submit button.Like Facebook comment.After posting the comment, I have verified that comment.Now I want to add 2nd comment and also want to verify this 2nd comment.So is there any way to verify the text/comment every time after posting? Thanks in advance.

Was it helpful?

Solution

You can try the following code:

protected boolean isTextPresent(String text){
        try{
            boolean b = driver.getPageSource().contains(text);
            return b;
        }
        catch(Exception e){
            return false;
        }
    }

String s[] = {"test comment1", "test comment2"};
        for(int i =0; i<s.length; i++){
            driver.findElement(By.name("comment_body[und][0][value]")).sendKeys(s[i]);
            driver.findElement(By.xpath("//a[@onclick='commnet_form_submit_handler(); return false;']")).click();
            assertTrue(isTextPresent(s[i]));
        }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top