[英]How to verify text everytime after posting with Selenium WebDriver using java?
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? 我有一个评论页面,人们可以在文本字段中写评论,然后单击“提交”按钮发表评论。就像Facebook的评论。发布评论后,我已经验证了该评论。现在我想添加第二条评论,并且还想验证第二条评论。因此,发布后每次有什么方法可以验证文本/评论吗? Thanks in advance.
提前致谢。
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]));
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.