多次点击selenium webdriver中的按钮

时间:2014-12-09 03:56:08

标签: java selenium-webdriver

如何在selenium webdriver中对按钮执行多次单击(4次),而不使用for循环? 目前我必须使用for循环点击一个按钮并使其工作,因为只需单击它就不起作用。

针对上述问题的任何解决方案?

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

2 个答案:

答案 0 :(得分:0)

尝试使用Java脚本执行器

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

答案 1 :(得分:-1)

你可以尝试:

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

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