gpt4 book ai didi

java - 如何在 Selenium Webdriver 中模拟鼠标双击

转载 作者:行者123 更新时间:2023-12-01 10:36:37 28 4
gpt4 key购买 nike

我希望能够像用户一样快速单击注销按钮两次?

WebElement logout = driver.findElement(By.id("dijit_form_Button_0_label"));{

if(logout.isDisplayed()){
logout.click();

我希望能够像用户一样在不到一秒的时间内单击注销按钮两次?这在 selenium webdriver 中可能吗?

最佳答案

编辑:

确保 dom 已加载

喜欢atri说,你可以按照This thread使用双击功能.

WebElement logout = driver.findElement(By.id("dijit_form_Button_0_label"));{

if(logout.isDisplayed()){
logout.doubleClick();

如果你不想使用doubleClick功能,我会推荐Selemium的ExplicitWait Selenium: Implicit and explicit Wait

如果您想手动执行此操作,可以使用 javascript Thread 和 selenium wait 在单击之间添加延迟。基于This thread

WebElement logout = driver.findElement(By.id("dijit_form_Button_0_label"));{

if(logout.isDisplayed()){
logout.click();
Thread.sleep(100);
logout.click();
}

Better way is to use ExplicitWaits which you means you will wait exactly as long as some action happens or some element gets rendered on the page. - petr-mensik

An explicit waits is code you define to wait for a certain condition to occur before proceeding further in the code. The worst case of this is Thread.sleep(), which sets the condition to an exact time period to wait. - Selenium

关于java - 如何在 Selenium Webdriver 中模拟鼠标双击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34681496/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com