gpt4 book ai didi

java - Selenium DoubleClick WebElement 导致错误

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

我使用下面的代码来刺激鼠标双击按钮,但是,我收到一个编译错误,该错误指向操作,但我不知道如何修复它。

Actions act = new Actions(driver);
act.doubleClick(driver.findElement(By.id("dijit_form_Button_0_label"))).build().perform();
logger1.info("Logout Successful");

org.testng.TestNGException:
Cannot instantiate class testNG.RAD3398LogoutTwiceTest
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.testng.internal.ObjectFactoryImpl.newInstance(ObjectFactoryImpl.java:29)
... 21 more
Caused by: java.lang.NullPointerException
at org.openqa.selenium.interactions.Actions.<init>(Actions.java:44)
at testNG.RAD3398LogoutTwiceTest.<init>(RAD3398LogoutTwiceTest.java:25)
... 26 more

有什么想法吗?

最佳答案

您可以尝试使用 javascript 触发双击事件。这就是我从 Selenium 触发点击事件的方法,我想你可以调整它来触发双击

    public static void phantomClick (WebDriver driver, WebElement element){
final String script = "function ghostclick(el){var ev = document.createEvent(\"MouseEvent\");ev.initMouseEvent(\"click\",true ,true,window,null,0,0,0,0,false,false,false,false,0,null);el.dispatchEvent(ev);} return ghostclick(arguments[0])";
((JavascriptExecutor) driver).executeScript(script, element);
}

关于java - Selenium DoubleClick WebElement 导致错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34718647/

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