Below is my sample code that take from this Stackoverflow question Not able to drag element using Actions
Sample code that used to find the webelement XY cordinates. By getting error "org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the remote browser. It may have died."
Or in the error printed on the eclipse console getting "Caused by: java.lang.NumberFormatException: For input string: "617.7"
WebDriver browser = new ChromeDriver();
browser.get("http://www.seleniumeasy.com/test/drag-and-drop-demo.html");
// Robot class uses Screen Coordinates, therefore, we need the fullscreen browser
// instead of maximised. so that the webpage coordinates are mapped to screen
// coordinates.
browser.manage().window().fullscreen();
WebElement itemToBeDragged = browser
.findElement(By.xpath(" (//h3[contains(.,'Items to Drag')]//following-sibling::span)[1]"));
WebElement whereToBeDragged = browser.findElement(By.xpath("//div[@id='mydropzone']"));
// robot class object to perform actual mouse events.
// import java.awt.Robot and java.awt.event.InputEvent
Robot robot = new Robot();
try {
robot.mouseMove(itemToBeDragged.getLocation().x+(int)itemToBeDragged.getSize().width/2, itemToBeDragged.getLocation().y+(int)itemToBeDragged.getSize().getHeight()/2);
Thread.sleep(1000);
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
robot.mouseMove(itemToBeDragged.getLocation().x+(int)itemToBeDragged.getSize().width/3, itemToBeDragged.getLocation().y+(int)itemToBeDragged.getSize().getHeight()/3);
Thread.sleep(1000);
Thread.sleep(1000);
robot.mouseMove(whereToBeDragged.getLocation().x+(int)whereToBeDragged.getSize().width/3, whereToBeDragged.getLocation().y+(int)whereToBeDragged.getSize().getHeight()/3);
Thread.sleep(1000);
robot.mouseMove(whereToBeDragged.getLocation().x+(int)whereToBeDragged.getSize().width/2, whereToBeDragged.getLocation().y+(int)whereToBeDragged.getSize().getHeight()/2);
Thread.sleep(1000);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
Thread.sleep(1000);
} catch (Exception e) {
e.printStackTrace();
}
Below is my Error what i get in Eclipse Console.
FAILED: DragnDrop
org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the remote browser. It may have died.
Build info: version: '2.53.0', revision: '35ae25b', time: '2016-03-15 16:57:40'
System info: host: 'Assembly-SRV-India-01', ip: '192.168.56.1', os.name: 'Windows Server 2019', os.arch: 'amd64', os.version: '10.0', java.version: '13.0.1'
Driver info: driver.version: RemoteWebDriver
Capabilities [{mobileEmulationEnabled=false, timeouts={implicit=0, pageLoad=300000, script=30000}, hasTouchScreen=false, platform=XP, acceptSslCerts=false, goog:chromeOptions={debuggerAddress=localhost:53007}, acceptInsecureCerts=false, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, setWindowRect=true, unexpectedAlertBehaviour=ignore, applicationCacheEnabled=false, rotatable=false, networkConnectionEnabled=false, chrome={chromedriverVersion=80.0.3987.106 (f68069574609230cf9b635cd784cfb1bf81bb53a-refs/branch-heads/3987@{#882}), userDataDir=C:\Users\ADMINI~1\AppData\Local\Temp\scoped_dir13692_615110410}, takesHeapSnapshot=true, pageLoadStrategy=normal, strictFileInteractability=false, databaseEnabled=false, handlesAlerts=true, version=80.0.3987.163, browserConnectionEnabled=false, proxy={}, nativeEvents=true, locationContextEnabled=true, cssSelectorsEnabled=true}]
Session ID: 3fd2a3a2ac16566e351a75da0844a4d4
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:665)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:327)
at org.openqa.selenium.remote.RemoteWebElement.getLocation(RemoteWebElement.java:380)
at login.onlinedraganddrop.DragnDrop(onlinedraganddrop.java:51)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:639)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:816)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1124)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
at org.testng.TestRunner.privateRun(TestRunner.java:774)
at org.testng.TestRunner.run(TestRunner.java:624)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:359)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:354)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:312)
at org.testng.SuiteRunner.run(SuiteRunner.java:261)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1215)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1140)
at org.testng.TestNG.run(TestNG.java:1048)
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)
**Caused by: java.lang.NumberFormatException: For input string: "617.7"**
at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:68)
at java.base/java.lang.Integer.parseInt(Integer.java:658)
at java.base/java.math.BigInteger.<init>(BigInteger.java:535)
at java.base/java.math.BigInteger.<init>(BigInteger.java:673)
at com.google.gson.internal.LazilyParsedNumber.longValue(LazilyParsedNumber.java:51)
at com.google.gson.JsonPrimitive.getAsLong(JsonPrimitive.java:233)
at org.openqa.selenium.remote.JsonToBeanConverter.convertJsonPrimitive(JsonToBeanConverter.java:249)
at org.openqa.selenium.remote.JsonToBeanConverter.convert(JsonToBeanConverter.java:75)
at org.openqa.selenium.remote.JsonToBeanConverter.convertMap(JsonToBeanConverter.java:344)
at org.openqa.selenium.remote.JsonToBeanConverter.convert(JsonToBeanConverter.java:219)
at org.openqa.selenium.remote.JsonToBeanConverter.convert(JsonToBeanConverter.java:43)
at org.openqa.selenium.remote.JsonToBeanConverter.convert(JsonToBeanConverter.java:144)
at org.openqa.selenium.remote.JsonToBeanConverter.convert(JsonToBeanConverter.java:43)
at org.openqa.selenium.remote.http.JsonHttpResponseCodec.decode(JsonHttpResponseCodec.java:78)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:145)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:644)
... 27 more