[英]How to know whether Text is asserted
在我的應用程序中,有一種情況是屏幕在2種情況下給出2種警報。 我需要聲明警報中的文本並關閉警報。
我使用了以下內容:
Alert javascriptAlert= driver.switchTo().alert();
String text= javascriptAlert.getText();
assertTrue(text.matches("Saved Successfully."));
javascriptAlert.accept();
使用此功能,我可以接受警報。 但是,即使顯示了其他一些警報,該警報也會關閉,並且不會顯示該警報是否與給定的文本匹配。
那么如何查找文本是否匹配?
您可以將布爾值設置為true(如果匹配),然后將其用於您的目的。 下面的示例方法:
public boolean matchAlertTextAndClose(String textToMatch){
Alert javascriptAlert= driver.switchTo().alert();
String text= javascriptAlert.getText();
boolean doesTextMatch = false;
if(text.matches(textToMatch)){
doesTextMatch = true;
}
else{
doesTextMatch = false;
}
javascriptAlert.accept();
return doesTextMatch;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.