1

I am new to Selenium. I am using gridlastic as test environment.

I have gone through Actions class for selenium which has methods to move mouse as well as got the mouse instance via web driver by calling getMouse() and tried to move the mouse but dint succeed.

@Test(enabled = true)
     public void test_site() throws Exception  {    
         Coordinates elementLocation = null;
        driver.get("https://www.amazon.com");

        Mouse mouse = ((HasInputDevices) driver).getMouse();
        System.out.println(mouse.toString());
        if(mouse==null) {
            System.out.println("mouse is null");    
        }
        WebElement element1=driver.findElementByXPath("//*[@id=\"a-autoid-0-announce\"]");
        elementLocation = ((Locatable) element1).getCoordinates();
        mouse.mouseMove(elementLocation);

        Thread.sleep(5000); //slow down for demo purposes


    }

Also tried using the actions class as well

@Test(enabled = true)
     public void test_site() throws Exception  {    
        driver.get("https://www.google.com/ncr");
        Actions builder = new Actions(driver);

        builder.
           moveByOffset( 100, 1 )
           .build().perform();
        Thread.sleep(10000); //slow down for demo purposes
        WebElement element = driver.findElement(By.name("q"));
        element.sendKeys("webdriver");
        element.submit();
        Thread.sleep(5000); //slow down for demo purposes
    }

Still dint succeed , the mouse pointer remains at position (0,0) always. Can anyone help how to do it.

enter image description here Please don't suggest using Robot Class from JAVA as the test environment is gridlastic and it doesn't work for it.

I also tried using the javascript executor, but its not possible as mouse cursor is controlled by operating system. I thought of changing values of window object clientX and clientY , but those are readonly as per documentation.

2 Answers 2

1

This seems very strange, but if you try the following code, you will see, that you do not see the moving mousepointer:

    PointerInput p = new PointerInput(PointerInput.Kind.MOUSE, "MyMouse");
    Interaction i = p.createPointerMove(Duration.ofSeconds(2), PointerInput.Origin.fromElement(element1), 5, 5);
    Actions builder = new Actions(driver);
    Action mouseOverHome = builder
            .tick(i).click()
            .build();
    mouseOverHome.perform();

I added the click to demonstrate the effect. I had to work with the shopping cart at //*[@id=\"nav-cart\"]. Your xpath expression was not visible for me. You will notice the mouseover effect of the cart icon before the click.

Sign up to request clarification or add additional context in comments.

7 Comments

which version of selenium are you using? The reason why i ask is because i cannot import PointerInput from selenium , other imports are able to import. I am using selenium 2.53.1
I tried with selenium 3.141.59 and was able to import successfully, however after the tests the mouse pointer was still at (0,0), You can watch this on video s3-us-west-2.amazonaws.com/6ca5b6bd-816f-45ea-b0af-d33a1627f21e/…
I m using the current Selenium 3.141.59, but any Selenium 3 version should fit. And the strange effect is, that the visible mouse pointer is not moving while the browser seems to have its own virtual mouse pointer.
Can you have a look at the video, i did try with your code suggestion, however the mouse pointer remains at (0,0). I need to move that mouse cursor
If you really need to move the visible mouse pointer, I do not have a solution. I do not expect to find a viable solution with webdriver. You can look at youtube.com/watch?v=mpp0zCX0R34 His mouse moves are working fine, but the visible mouse pointer does not move at all.
|
0

You can control the mouse point with AutoIT. You'll need to start your AutoIT script from your Selenium runtime environment (looks like you're using java) Here's the code to call your AutoIT script:

//Some arbitrary example Selenium code...
driver.findElement(By.id("input_4")).click();           
// below line execute the AutoIT script .
Runtime.getRuntime().exec("E:\\AutoIT\\FileUpload.exe");    

I found this example from guru99.com thanks to Gaurav Nigam. Here's the link How to use AutoIT with Selenium Webdriver: File Upload Example

In your AutoIT script you need some "Mouse Move" commands:

MouseMove(10, 100) ; Move the mouse cursor to the x, y position of 10, 100.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.