简体   繁体   English

使用Java在Selenium WebDriver中发布后,每次如何验证文本?

[英]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.

相关问题 如何在网页上使用带有 Java 的 Selenium WebDriver 验证工具提示文本 - How to verify tooltip text using Selenium WebDriver with java on a webpage 如何使用Java验证Selenium WebDriver中的tooltipText - How to verify tooltipText in Selenium WebDriver using Java 如何验证特定文本下的文本 <DIV> 使用Selenium WebDriver(java)和Chrome浏览器标记? - How can I verify presence of text under a specific <DIV> tag using Selenium WebDriver (java) and Chrome? 如何使用Selenium Webdriver验证模式对话框中的文本 - How to verify the text present in the modal dialog using Selenium Webdriver 如果对象在Selenium Webdriver Java中不可见,如何使用xpath验证对象 - how to verify object using xpath if object is invisible in selenium webdriver java 如何使用Java使用Selenium WebDriver验证是否单击了按钮 - How to verify whether a Button is clicked or not with Selenium WebDriver using Java 如何使用Java在Selenium Webdriver中验证单词是否为粗体? - How to verify that a word is Bold in selenium webdriver using Java? 如何使用Java使用Selenium WebDriver验证动态库? - How to verify dynamic gallery with Selenium WebDriver using Java? 如何验证 selenium webdriver 中的文本颜色? - How to verify text color in selenium webdriver? 如何在Selenium Java Webdriver中验证图像的尺寸? - How to verify dimensions of image in Selenium Java Webdriver?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM