How to move the mouse pointer and click with Selenium Webdriver JavaScript?

selenium move mouse to coordinates c#
move mouse pointer in selenium python
selenium move mouse to element
selenium get mouse position
mouse move in selenium c#
move to element in selenium
click in selenium
selenium javascript click

I'm new in selenium and I'm facing problems with simple tasks.

I'm trying to move the mouse to a specific area (x, y coordinates) in the page and then, click, but without success. I did read the documentation and I'm using {bridge: true} because of the chromewebdriver.

Here is my code:

var webdriver = require('selenium-webdriver'),
  By = webdriver.By,
  until = webdriver.until,
  Origin = webdriver;

var driver = new webdriver.Builder()


var actions = driver.actions({ bridge: true });

actions.mouse().move({x: 400, y: 1100, duration: 2000, origin: Origin.VIEWPORT});

Another question. I know there is a fourth parameter origin origin: Origin.VIEWPORT, however, I don't know if I imported it correctly.

I also don't know how to trigger the click event since I have not any selected element. I want to click in the final mouse pointer position.

It seems that you are missing the .perform();.

The classic way to do this is with Protractor

 // Instead of specifying an element as the target, you can specify an offset
// in pixels. This example double-clicks slightly to the right of an element.
    mouseMove({x: 50, y: 0}).

You can use mouseMove to the x y of the body element.

Hope this helps you!


If this doesn't work for you try something like this:

browser.actions() .mouseMove(element, { x: 20, y: 75, }) .perform().then(() => browser.actions() .click() .perform());

Mouse Hover Actions in Selenium Webdriver, has link text "Admin"): Actions mouseHover = new Actions(driver); mouseHover. MoveToElement(driver. FindElement(By. Mouse Hover Action in Selenium. Let’s just start understanding moveToElement method of Actions class. 1. How to move the mouse cursor to the middle of the web element? moveToElement(WebElement target): Moves the mouse to the middle of the element. First, instantiate an Actions class: Actions actions = new Actions(driver);

its works to me

WebElement button = driver.findElement(By.xpath("//div[@class='page-button']"));
//new 一個移動滑鼠的物件
Actions clickAction = new Actions(driver).click(button);

selenium-webdriver, from the top-left corner. A negative value means coordinates above the element. require 'selenium-webdriver' driver = Selenium:: WebDriver. for :chrome begin # Navigate to Url driver. get '' # Store 'Gmail' anchor web element gmail_link = driver. find_element(link_text: 'Gmail') # Performs mouse move action onto the element driver. action. move_to(gmail_link). perform ensure driver. quit end

WebDriver driver = new FirefoxDriver();
JavascriptExecutor scpt = (JavascriptExecutor)driver;
scpt.executeScript("document.getElementById('[insert id]').click();");

Make sure you add a timer sleep in so it can let the page load and then be able to click afterwards so use Thread.Sleep();

Actions, 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 How to mouse hover on a web element using Selenium WebDriver? R Tutorial · Java Programs · JavaScript Reserved Words and Keywords  mouseMove (int x, int y): This method moves the mouse pointer to the given screen position. Here, x is X position, and y is Y position in the coordinates. For Example, the method mouseMove (100, 50) will move the mouse pointer to the x coordinate 100 and y coordinate 50 on the screen. How to perform mouse click in Selenium using Robot class?

How to move mouse pointer to element in Selenium with nodejs , With the actions object you should first move the menu title, and then move to the sub menu item and click it. First we need to create new action builder instance by​  In this tutorial, we will be studying the advanced mouse interactions using Actions class. Using these methods,we can perform mouse operations like right click, double click, mouse hover, click and hold etc. Actions Class Method for Mouse Interactions click()-This method is used to click at the current mouse pointer position.

Moving mouse pointer to a specific location or element using C# and , actions in Selenium WebDriver with Java - mouse hover, right click, This method is used to click at the current mouse pointer position. Mouse Hover Action in Selenium: What is Mouse Hover? Mouse hover, which is called simply hover, triggers an event when a user assigns a mouse to the specified location, such as the action taken to move the mouse over a hyperlink item on a web page, such as a pop-up window or a description box Causes.

Mouse Actions in Selenium WebDriver, It will move to the element and performs a double-click in the middle of the given element. Java Python C# Ruby JavaScript. Kotlin. How may I declare a test step(not a test case) as optional in Selenium Webdriver when using Page Object Model? How may I click on the load more button repeatedly until the very last item in the page has been loaded? How may I test a browser extension with Selenium WebDriver? How to scroll a page vertically by 80px with Selenium Webdriver and Java?

  • I guess you should add click() and perform() into the chain
  • I added .click().perform() and got click is not a function error.
  • What language is this? Add the tag to the question!
  • Hi @SiKing, it's JavaScript. I added the tag. Thanks.
  • I have edited my answer...
  • Please add your comments in English, not all users may be able to understand Chinese.
  • The OP is asking for x,y coordinates, not element by id!
  • Hi @Xion, thanks to answer. Actually, it's not my problem. I already can click in any element. My question is how can I move the mouse to a blank area, and then, click. Thanks anyway.