简体   繁体   English

多次单击 selenium webdriver 中的按钮

[英]Multiple click on a button in selenium webdriver

How to perform multiple clicks on a button (4 times) in selenium webdriver, without making use of for loop?如何在不使用 for 循环的情况下在 selenium webdriver 中多次单击按钮(4 次)? Currently I have to make use of for loop to click on a button and make it work because on a single click it doesn't work.目前我必须使用 for 循环来单击一个按钮并使其工作,因为单击它不起作用。

Any solution for the above question?以上问题有什么解决办法吗?

for (int i=1; i<=4; i++) {
    driver.findElement(By.xpath(".//*[@id='body']/div[6]/div[1]/div[3]/div[1]/ul/li[5]/a")).click();
}

Thread.sleep(1000);
driver.findElement(By.xpath(".//*[@id='body']/div[6]/div[1]/div[3]/div[2]/div[1]/input")).sendKeys("7");
driver.findElement(By.xpath(".//*[@id='body']/div[6]/div[1]/div[3]/div[2]/div[2]/input")).sendKeys("8");
driver.findElement(By.xpath(".//*[@id='body']/div[6]/div[1]/div[3]/div[2]/div[3]/input")).sendKeys("9");
driver.findElement(By.xpath(".//*[@id='body']/div[6]/div[1]/div[3]/div[1]/ul/li[7]/a/div[2]")).click();
driver.findElement(By.linkText("demobase")).click();

尝试 Java Script Executor

WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(60)); wait.Until(driver1 => ((IJavaScriptExecutor)driver).ExecuteScript("return document.readyState").Equals("complete")); IWebElement saveBtn = wait.Until(ExpectedConditions.ElementToBeClickable(By.Xpath("//*[@id='body']/div[6]/div[1]/div[3]/div[1]/ul/li[5]/a"))); ((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].click()", saveBtn);

You could try:你可以试试:

WebElement we = findElement (By.xpath("path "));

Actions a = new Actions();
a.doubleClick(we).perform();
a.doubleClick(we).preform();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM