我想根据特定格式检查 UI 文本的格式,例如C165433、A636673等 一种方法是从 UI 检索文本并使用正则表达式进行匹配,如果 matches() 的结果为真,则通过测试用例,否则抛出异常说明不匹配。我知道 webdriver 中没有 matches() 以任何其他方式在 xpath 中匹配来自 UI 的字符串
最佳答案
是的,matches()
function is not available for use via webdriver at the moment .
您必须使用编程语言进行匹配,例如在 Java 中:
WebElement element = driver.findElement(By.id("myid"));
String value = element.getText();
assertTrue(value.matches("[A-Z][0-9]{6}"));
关于java - 检查xpath中的字符串格式和数字格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38810577/