Selenium MoveToElement Action is not working - selenium

On performing MoveToElement Action,Mouse hasnt moved to the element location.Please find the below code.
Actions action = new Actions(driver);
action.MoveToElement(element);
action.Build().Perform();

You can try the below code:
IWebElement element = driver.FindElement(By.Id("Login_Id"));
Actions action = new Actions(driver);
action.MoveToElement(element);
action.Build().Perform();

Related

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.
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/
Skip the build() part, perform() does it underneath anyway.
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.
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();
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();
}
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)));
I have solved this problem with:
const element = await driver.findElement(...)
await driver.executeScript("arguments[0].scrollIntoView(true);", element)
await driver.sleep(500);

Drag and drop not working - Selenium Webdriver

I am trying to drag an element into another element using Selenium WebDriver but it's not working.
We tried with different solutions as mentioned below :
Application was built on Anjular4
WebElement From = (driver.findElement(By.xpath("")));
WebElement To = (driver.findElement(By.xpath("//*[#id='avpContainer']"));
Actions builder = new Actions(driver);
builder.clickAndHold(From).moveToElement(To).click(To).release().build().perform();
WebElement From = (driver.findElement(By.xpath("")));
WebElement To = (driver.findElement(By.xpath("//*[#id='avpContainer']"));
Actions builder = new Actions(driver);
builder.clickAndHold(From).release(To).build().perform();
WebElement From = (driver.findElement(By.xpath("")));
WebElement To = (driver.findElement(By.xpath("//*[#id='avpContainer']"));
Actions builder = new Actions(driver);
builder.dragAndDrop(From, To).build().perform();
//Setup robot
Robot robot = new Robot();
robot.setAutoDelay(50);
//Maximized browser:
robot.keyPress(KeyEvent.VK_F11);
Thread.sleep(2000);
WebElement dragElement = d.findElement('drag element');
Actions builder = new Actions(d);
builder.dragAndDropBy(dragElement,x, y).build().perform();
Can anyone help to resolve this issue.
WebElement From = driver.findElement(By.xpath(""));
WebElement To = driver.findElement(By.xpath(""));
Actions builder = new Actions(driver);
Action dragAndDrop = builder.clickAndHold(From)
.moveToElement(To)
.release(To)
.build();
dragAndDrop.perform();
Drag and Drop functionality won't work, if application is built on HTML5.
So, we can make this work with the support of draganddrop.js

NoSuchElementException on performing Mousehover action in selenium

I have a webpage in which I am trying to perform a mouse hover.. There is an element named "Entity Records" on which if you hover your mouse it displays a menu. In that menu I need to click on an element named Create New record.
I have tried 3 different set of codes but it's not working for me..
1st One:
WebElement el = driver.findElement(By.xpath("\\...."));
action.moveToElement(el).build().perform();
Actions builder = new Actions(driver);
builder.moveToElement(driver.findElement(By.cssSelector("..."))).click().build().perform();
2nd one:
WebElement entityrecordsmenu = driver.findElement(By.cssSelector("..."));
Actions builder = new Actions(driver);
builder.moveToElement(entityrecordsmenu).build().perform();
WebElement createnewrecord = driver.findElement(By.cssSelector("..."));
createnewrecord.click();
3rd one:
Actions action2 = new Actions(driver);
WebElement ele = driver.findElement(By.xpath("...));
action2.moveToElement(ele).build().perform();
Actions build2 = new Actions(driver);
build2.moveToElement(driver.findElement(By.xpath("..."))).click().build().perform();
1st and 2nd code are doing the mouse hover fine, but its not clicking on the menu element. Can anyone suggest me the correct way of doing this?
After mouse hover, try by giving some wait to get that element displayed and then click.
WebElement entityrecordsmenu = driver.findElement(By.cssSelector("..."));
Actions builder = new Actions(driver);
builder.moveToElement(entityrecordsmenu).build().perform();
//provide wait here to display dropdown
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
//some time implicity wait may fails then use thread.sleep
//Thread.sleep(3000);
WebElement createnewrecord = driver.findElement(By.cssSelector("..."));
createnewrecord.click();
//if still above once does not work you can try
Actions builder1 = new Actions(driver);
builder1.moveToElement(entityrecordsmenu).click(driver.findElement(By.cssSelector("..."))).build().perform();
Thank You,
Murali

How to select the submenu of the flyout using selenium webdriver

I want to select the submenu of the flyout using selenium webdriver.
Also how can I simulate on hover on menu items using selenium.
Please guide or provide some tutorial for the same.
Thanks
Check the actions class, something like this you need:
WebElement element = driver.findElement(By.Id("id"));
Actions builder = new Actions(driver);
Actions hover = builder.moveToElement(element);
hover.build().perform();
String New_select_Just_Landed = "//*[#id='nav1']/a";
WebElement Ba = driver.findElement(By.xpath(New_select_Just_Landed));
WebElement subBa = driver.findElement(By.xpath("//*[#id='nav1']/section/ul/li/a"));
Actions action = new Actions(driver);
action.moveToElement(Ba).perform();
Thread.sleep(2000); System.out.println("Mouse hoover succeed");
action.moveToElement(subBa).perform();
subBa.click();
System.out.println("Click Just Landed! succeed");
Thread.sleep(5000L);

How to do mouseover using webdriver actions?

I'm trying to get element that appear after a mouseover action. how to do ?
I tried:
Actions action = new Actions(driver);
action.moveToElement(elem);
action.perform();
WebElement myDynamicElement = (new WebDriverWait(driver,10)).until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("class*='hoverEverywhereTooltip'")));
this element appear just after the mouse over event.
Try this.
code:
Actions actions = new Actions(driver);
WebElement menuhover = driver.findElement(By.linkText("Menu"));
actions.moveToElement(menuhover);
WebElement subLink = driver.findElement(By.id("submenu"));
actions.moveToElement(submenu);
actions.click();
actions.perform();
it worked I missed [] in my cssSelector properties:
WebElement myDynamicElement = (new WebDriverWait(driver,10)).until(ExpectedConditions.presenceOfElementLocated(By.c‌​ssSelector("[class*='hoverEverywhereTooltip']")));