【发布时间】:2017-03-01 18:31:05
【问题描述】:
我正在编写一个 selenium webdriver java 测试,并试图计算出现的名字后面没有姓氏的数量。
例如,任何时候出现“John Smith”都不会被计算在内,但如果是“John did this”这样的句子,由于Smith没有出现,就会增加计数。
不幸的是,无论我做什么,尝试从 WebElement 读取/计数都会返回 0,但我知道无论哪种方式我都不会排除姓氏条目。欢迎提出任何建议!
当前代码:
//get string from WebElement text
`String john = JohnSmith.getText();
int johnCount =0;
while (john.contains("john")){
johnCount++;
//this line starts from the substring after the first john
john = john.substring(john.indexOf("john") + "john".length());
}
【问题讨论】:
-
你需要正则表达式来做一些过滤
标签: java selenium selenium-webdriver count