嗨我有一个场景,我需要点击相似的按钮,饲料屏幕上的喜欢计数器将增加1现在我需要使用硒验证此计数器,如果它实际上增加,因为我不'知道旧的价值是什么,新的价值是什么。
我们可以使用selenium吗
答案 0 :(得分:0)
嗨,你可以像下面这样做
// this web-site shows counter ,its same like clicking on like button of face-book
// here instead of clicking we are refreshing the page or opening the same url again and again
driver.get("https://www.counter.gd/");
// finding the initial value of the counter is :
String initialCounter = driver.findElement(By.xpath("//*[@name='counter_id']")).getAttribute("value");
// printing the value of the counter, also converting the output type to int.
int countervalBefore = Integer.parseInt(initialCounter);
System.out.println("value of the counter before click/refresh is : " + countervalBefore);
// now refresh the page to increase the counter or click like button of the facebook to increase like counter
driver.navigate().refresh();
// now call the counter again
String afterCounter = driver.findElement(By.xpath("//*[@name='counter_id']")).getAttribute("value");
int countervalAfter = Integer.parseInt(afterCounter);
System.out.println("value of the counter after click/refresh is : " + countervalAfter);
// now verifying the previous counter value with current counter value
if(countervalAfter > countervalBefore){
System.out.println("Counter worked i.e incremented");
}else{
System.out.println("Counter not working");
}
希望这能解决您的问题。