Selenium 自动化测试中对页面元素的value比较验证 java语言


源代码:

public boolean verifyText(String elementName, String expectedText) {
String actualText = getValue(elementName);
if (actualText.equalsIgnoreCase(expectedText)) {

passed("Verify text on " + " " + elementName + " with text"
+ expectedText + "", "Text" + expectedText
+ " should be verified", "verified successfully");

return true;
}
failed("Verify text on " + " " + elementName + " with text"
+ expectedText + "", "Text" + expectedText
+ " should be verified", "verified unsuccessfully");
return false;
}

 

1. 对于页面上面的元素,我们给一个别名elementName;

2. 这个元素的期待值,或者说期待输出为expectedText;

3. 元素获取之后,实际的输出为actualText;

Selenium 帮助我们做了什么? 这里的Selenium在String actualText = getValue(elementName); 这句话中涉及的getValue方法,其实可以通过下面selenium的自带方法getAttribute来实现:

String org. openqa. selenium. WebElement. getAttribute( String arg0)
 
 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM