如何使用带有 Java 的 Selenium WebDriver 多次单击同一个按钮
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21413065/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to click on a same button multiple times using Selenium WebDriver with Java
提问by KhalDrogo
I tried searching for this but had 0 luck with this. Here's my problem, on my webpage I have a button that at every click generates some data. I'm trying to automate this so Selenium could keep clicking on it for, say 50 times, after every 2 seconds and I can verify that the data is being generated correctly. How do I formulate my for loop to achieve this. Help is greatly appreciated.
我尝试搜索此内容,但运气为 0。这是我的问题,在我的网页上,我有一个按钮,每次点击都会生成一些数据。我正在尝试自动执行此操作,以便 Selenium 可以在每 2 秒后继续单击它,例如 50 次,并且我可以验证数据是否正确生成。我如何制定我的 for 循环来实现这一点。非常感谢帮助。
回答by Ittiel
Here's a sample:
这是一个示例:
for (int i = 0; i < 50; i++){
//click the button
driver.findElement(By.xpath(xpath).click();
//wait 2 seconds
Thread.sleep(2000);
//check that data is being generated correctly
...
}