为什么拖放在使用 Selenium Web 驱动程序 (3.14.0) 的 IE 11 中不起作用?

问题描述

我正在尝试在 IE 浏览器(版本 11)上执行拖放操作。

public void DragAndDrop(String source,String target) throws InterruptedException,IOException {
    try {
        String basePath = new File("").getAbsolutePath();

        // http://stackoverflow.com/questions/29381233/how-to-simulate-html5-drag-and-drop-in-selenium-webdriver
        // https://gist.github.com/rcorReia/2362544
        final String JQUERY_LOAD_SCRIPT = (basePath + "/src/test/resources/jquery_load_helper.js");
        String jQueryLoader = readFile(JQUERY_LOAD_SCRIPT);

        driver.manage().timeouts().setScriptTimeout(10,TimeUnit.SECONDS);

        JavascriptExecutor js = (JavascriptExecutor) driver;
        js.executeAsyncScript(jQueryLoader /*,http://localhost:8080/jquery-1.7.2.js */);

        // ready to rock
        js.executeScript("jQuery(function($) { "
                + " $('input[name=\"q\"]').val('bada-bing').closest('form').submit(); " + " }); ");
        // http://stackoverflow.com/questions/29381233/how-to-simulate-html5-drag-and-drop-in-selenium-webdriver
        // "where jquery_load_helper.js contains:"
        String filePath = basePath + "/src/test/resources/drag_and_drop_helper.js";

        // JQuery can ONLY work with id and css,xpath does NOT work with it.
        // String source = "//section[@id='wrapper']/article/ul/li[4]/a";

        StringBuffer buffer = new StringBuffer();
        String line;
        BufferedReader br = new BufferedReader(new FileReader(filePath));
        while ((line = br.readLine()) != null)
            buffer.append(line);

        String javaScript = buffer.toString();

        javaScript = javaScript + "$('" + source + "').simulateDragDrop({ dropTarget: '" + target + "'});";
        ((JavascriptExecutor) driver).executeScript(javaScript);

        Thread.sleep(1000);
    } catch (Exception e) {
        e.printstacktrace();
    }
}

IEDriverServer.exe 版本为 3.14.0.0

以下是我在执行时遇到的异常。

org.openqa.selenium.JavascriptException: Error executing JavaScript
Build info: version: '3.14.0',revision: 'aacccce0',time: '2018-08-02T20:19:58.91Z'
System info: host: 'PRASHANTN',ip: '172.20.1.24',os.name: 'Windows 10',os.arch: 'amd64',os.version: '10.0',java.version: '15.0.2'
Driver info: org.openqa.selenium.ie.InternetExplorerDriver
Capabilities {acceptInsecureCerts: false,browserName: internet explorer,browserVersion: 11,javascriptEnabled: true,pageLoadStrategy: normal,platform: WINDOWS,platformName: WINDOWS,proxy: Proxy(),se:ieOptions: {browserAttachTimeout: 0,elementScrollBehavior: 0,enablePersistentHover: true,ie.browserCommandLineswitches:,ie.ensureCleanSession: false,ie.fileUploadDialogTimeout: 3000,ie.forceCreateProcessApi: false,ignoreProtectedModeSettings: false,ignoreZoomSetting: false,initialbrowserUrl: http://localhost:18913/,nativeEvents: true,requireWindowFocus: false},setwindowRect: true,timeouts: {implicit: 0,pageLoad: 300000,script: 30000}}
Session ID: a7a07929-b969-44cd-9db4-2e7d09406d28
    at jdk.internal.reflect.GeneratedConstructorAccessor28.newInstance(UnkNown Source)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:548)
    at org.openqa.selenium.remote.RemoteWebDriver.executeScript(RemoteWebDriver.java:485)
    at pageObjects.BasePage.DragAndDrop(BasePage.java:856)
    at pageObjects.MonitoringPage.dragNDrop(MonitoringPage.java:695)
    at testCases.MonitoringViewTest.selectCloseMenuOnCamToolbar(MonitoringViewTest.java:1330)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:564)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:132)
    at org.testng.internal.TestInvoker.invokeMethod(TestInvoker.java:599)
    at org.testng.internal.TestInvoker.invokeTestMethod(TestInvoker.java:174)
    at org.testng.internal.MethodRunner.runInSequence(MethodRunner.java:46)
    at org.testng.internal.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:822)
    at org.testng.internal.TestInvoker.invokeTestMethods(TestInvoker.java:147)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:128)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
    at org.testng.TestRunner.privateRun(TestRunner.java:764)
    at org.testng.TestRunner.run(TestRunner.java:585)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:384)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:378)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:337)
    at org.testng.SuiteRunner.run(SuiteRunner.java:286)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1218)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1140)
    at org.testng.TestNG.runSuites(TestNG.java:1069)
    at org.testng.TestNG.run(TestNG.java:1037)
    at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...