Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何点击几秒钟_Java_Selenium - Fatal编程技术网

Java 如何点击几秒钟

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单击“确定”:

第一个帖子。。。 我发现了javascript和selenium,我正在尝试左键单击,持续时间为1或2秒。 右键单击或双击很容易,但是如何长时间单击呢

谢谢你的支持

双击即可:

 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以按下按钮开始,以释放按钮结束