Java 如何点击几秒钟
第一个帖子。。。 我发现了javascript和selenium,我正在尝试左键单击,持续时间为1或2秒。 右键单击或双击很容易,但是如何长时间单击呢 谢谢你的支持 双击即可:Java 如何点击几秒钟,java,selenium,Java,Selenium,第一个帖子。。。 我发现了javascript和selenium,我正在尝试左键单击,持续时间为1或2秒。 右键单击或双击很容易,但是如何长时间单击呢 谢谢你的支持 双击即可: Actions action = new Actions(driver); WebElement link = driver.findElement(By.ID ("Element ID")); action. doubleClick (link).perform(); 用executeScript单击“确定”:
Actions action = new Actions(driver);
WebElement link = driver.findElement(By.ID ("Element ID"));
action. doubleClick (link).perform();
用executeScript单击“确定”:
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("document.querySelector(script).click();",Arguments);
此时,我没有长时间单击的轨迹…您可以尝试下面的选项
public void loingClick(WebDriver driver,WebElement element, int numberOfSeconds) throws Exception
{
Actions action = new Actions(driver);
action.clickAndHold(element).build().perform();
Thread.sleep(1000*numberOfSeconds);
action.moveToElement(element).release();
}
非常感谢,它工作得很好。我认为clickandHold以按下按钮开始,以释放按钮结束