Moving mouse pointer to a specific location or element using C# and Selenium

0 votes

I am performing a click operation using Selenium and C#.I am able to perform click operation but I am not able to move mouse pointer(cursor) to a specific co-ordinate or over specific element.

Below is the code I’m using.

Actions action = new Actions(driver);

action.MoveByOffset(500, 500).ContextClick().Perform();

Jun 25, 2018 in Selenium by Martin
• 4,330 points
19,277 views
 ChromeDriver driver = new ChromeDriver();
   Actions action = new Actions(driver);

   action.MoveByOffset(5,5).Perform();  //moves cursor to point (5,5)

   action.MoveByOffset(10, 15).Perform();  //moves cursor to point (10,15)

2 answers to this question.

0 votes

Rather than trying to get an element just move by offset. Make sure you know what your prior focus is... If none then it should be the top left corner of the page. Then put your sleep in the middle and you should be able to see the mouse move, wait, and then click.

Actions action = new Actions(driver);
action.MoveByOffset(200,100).Perform();
Thread.Sleep(10000);
action.Click();

answered Jun 25, 2018 by Samarpit
• 5,890 points
0 votes

Hi, I will Share my ideas.

Here is a piece of code where we can move the mouse pointer to a location and clicking on the moved region

import org.openqa.selenium.WebElement;

import org.openqa.selenium.interactions.Actions;

Actions builder = new Actions(driver);  

WebElement Element = driver.findElement(By.xpath("//div[@id='signUpModal']")); 

builder.moveToElement(Element, 100, 100).click().build().perform();

Note: The Pointer will move with reference to region of element described "Element"(Top left of Element region is considered as 0,0).

Click here for more information

answered Mar 18, 2019 by Ellen Dares

Related Questions In Selenium

0 votes
1 answer
0 votes
1 answer

How to mouse hover on a web element using Selenium WebDriver?

Hello Nitin, to automate mouse hovering over ...READ MORE

answered May 7, 2019 in Selenium by Anvi
• 14,110 points
3,265 views
0 votes
2 answers

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,510 points
3,531 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31 in Selenium by Sri
• 2,970 points
4,534 views
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,890 points
2,596 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 2 in Selenium by Sri
• 2,970 points
2,863 views
0 votes
1 answer

How To move physical mouse pointer in selenium and c#

You can't show the mouse pointer moving and ...READ MORE

answered Jun 4, 2018 in Selenium by Samarpit
• 5,890 points
2,129 views
+1 vote
1 answer