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,320 points
50,323 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)

5 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,910 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).

For further understanding, you can refer to the Selenium Training.

answered Mar 18, 2019 by Ellen Dares
0 votes
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)

answered Oct 19, 2020 by BrainBeast

edited Oct 19, 2020 by Gitika
0 votes

Selenium get mouse position

Moving mouse pointer to a specific location or element using C# and , Actions action = new Actions(driver); action. MoveByOffset(500, 500). ContextClick​(). Perform();.

answered Dec 16, 2020 by Rajiv
• 8,910 points
0 votes

n order to perform a 'mouse hover' action, we need to chain all of the actions that we want to achieve in one go. So move to the element that which has sub elements and click on the child item. It should the same way what we do normally to click on a sub menu item.

answered Dec 16, 2020 by Gitika
• 65,890 points

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,150 points
6,490 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,500 points
13,568 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

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

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
9,084 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,910 points
7,178 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 3, 2020 in Selenium by Sri
• 3,190 points
7,840 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,910 points
3,899 views
+1 vote
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP