eastwater
eastwater

Reputation: 5560

Selenium java webdriver 3: moveToElement not working

Selenium java webdriver 3: moveToElement not working.

WebElement element = ...
Actions actions = new Actions(driver);
actions.moveToElement(element).build().perform();

Tried, adding click()

WebElement element = ...
Actions actions = new Actions(driver);
actions.moveToElement(element).click().build().perform();

Not working. The mouse is not moved.

Upvotes: 1

Views: 7311

Answers (7)

Masih Jahangiri
Masih Jahangiri

Reputation: 10897

I have solved this problem with:

const element = await driver.findElement(...)
await driver.executeScript("arguments[0].scrollIntoView(true);", element)
await driver.sleep(500);

Upvotes: 0

CCC
CCC

Reputation: 200

if you need to click the element you could try javascript:

JavascriptExecutor executor = (JavascriptExecutor)driver;
        executor.executeScript("arguments[0].click();", driver.findElement(By.xpath(xPath)));

Upvotes: 0

Nagarjuna Yalamanchili
Nagarjuna Yalamanchili

Reputation: 710

Try below code

public static void mouse_movement(WebDriver driver, String xpathExpression) {
    Actions act = new Actions(driver);
    WebElement target = driver.findElement(By.xpath(xpathExpression));
    act.moveToElement(target).build().perform();
}

Upvotes: 0

Ahmad Maged
Ahmad Maged

Reputation: 1

try to find element by xpath rather than link text. it worked for me.

WebElement element = driver.findElement(By.xpath("..."));
Actions actions = new Actions(driver);
actions.moveToElement(element).build().perform();

Upvotes: 0

Neh18
Neh18

Reputation: 1

Actions actions = new Actions(driver);
WebElement element = driver.findElement(By.linkText("host"));
actions.moveToElement(element).build().perform();

This will work. first check your "find element" method is write or wrong. Please post this step as well. otherwise your code is correct.

Upvotes: 0

SAK
SAK

Reputation: 46

WebElement abcd = ..........

Actions actions = new Actions(driver);

actions.moveToElement(abcd).perform();

Above code will work, but please check with the chrome.exe version and the chrome version you are using it your machine. both should be compatible to one another. Check the compatibility with below link.

https://sites.google.com/a/chromium.org/chromedriver/

Upvotes: 2

Moro
Moro

Reputation: 939

Skip the build() part, perform() does it underneath anyway.

Upvotes: 0

Related Questions