简体   繁体   中英

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? 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.

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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