簡體   English   中英

使用Java在Selenium WebDriver中發布后,每次如何驗證文本?

[英]How to verify text everytime after posting with Selenium WebDriver using java?

我有一個評論頁面,人們可以在文本字段中寫評論,然后單擊“提交”按鈕發表評論。就像Facebook的評論。發布評論后,我已經驗證了該評論。現在我想添加第二條評論,並且還想驗證第二條評論。因此,發布后每次有什么方法可以驗證文本/評論嗎? 提前致謝。

您可以嘗試以下代碼:

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM