-1

我使用硒在我的系統中向客戶註冊某些東西。 響應是我想確保測試正常。在硒測試中驗證文本的一部分

的迴應是:

<div class="ui-messages-info ui-corner-all"> 
<span class="ui-messages-info-icon"></span> 
<ul> 
<li> 
<span class="ui-messages-info-summary">Name Name was registered - torsdag 02.03.2017 kl. 09.38.</span> 
</li> 
</ul> 
</div> 
</div> 

我想驗證文本「已註冊」是存在的,如果文字是不存在的測試失敗。

如何在硒中寫入檢查?

我的想法是這樣的:

WebElement verify = driver.findElement(By.something("was registered")); 
+0

提到這個問題和答案。 http://stackoverflow.com/questions/41974209/what-is-the-actual-difference-between-assertequals-vs-asserttrue-in-testng –

回答

0
String el_text = driver.findElement(By.class("ui-messages-info-summary")).getText(); 

,然後檢查其內部

if "was registered" is in el_text: 
0

試試這個,

driver.find_elements_by_xpath("//*[contains(text(), 'was registered')]") 

如果此元素是意味着它有文字「已註冊」。