Actions <object name>= new Actions("<driver object>");
<object name>.moveToElement(<driver object>.findElement(By.linkText("<value>")).build().perform();
----- Action part will be working within the browser.
Here for mouse over we need to create Actions object by giving drivers object. And using Actions object we can do moveToElement method on a web element.
- to perform few more operations after moving the mouse
After you make moveToElement is made, if you have list of options in it, so better do again moveToElement and then find the element and click it.
- Source: http://stackoverflow.com/questions/17293914/how-to-perform-mouseover-function-in-selenium-webdriver-using-java
Code:
Using the Actions to hover and the standard WebDriver click, I could hover and then click.
Scenario:
To click the sign in button in Amazon home page:
act1.moveToElement(obj2).moveToElement(obj2.findElement(By.xpath("//*[@id='nav-flyout-ya-signin']/a/span"))).click().build().perform();
support: http://stackoverflow.com/questions/17293914/how-to-perform-mouseover-function-in-selenium-webdriver-using-java
Notes:
moveToElment() - Moves the mouse to an offset from the top-left corner of the element.
perform() - A convenience method for performing the actions without calling build() first.
build() - Generates a composite action containinig all actions so far, ready to be performed (and resets the internal builder state, so subsequent calls to build() will contain fresh sequences).
<object name>.moveToElement(<driver object>.findElement(By.linkText("<value>")).build().perform();
----- Action part will be working within the browser.
Here for mouse over we need to create Actions object by giving drivers object. And using Actions object we can do moveToElement method on a web element.
- to perform few more operations after moving the mouse
After you make moveToElement is made, if you have list of options in it, so better do again moveToElement and then find the element and click it.
- Source: http://stackoverflow.com/questions/17293914/how-to-perform-mouseover-function-in-selenium-webdriver-using-java
Code:
- Hover over a menu item.
- Find the hidden element that is ONLY available after the hover.
- Click the sub-menu item.
Actions builder = new Actions(driver);
builder.moveToElement(hoverElement).perform();
builder.moveToElement(clickElement).click().perform();
This did not work for me. The following worked for me:Actions builder = new Actions(driver);
builder.moveToElement(hoverElement).perform();
By locator = By.id("clickElementID");
driver.click(locator);
Using the Actions to hover and the standard WebDriver click, I could hover and then click.
Scenario:
To click the sign in button in Amazon home page:
Solution:
WebElement obj2 = obj1.findElement(By.xpath("//*[@id='nav-link-yourAccount']/span[2]")); //My account element
Actions act1 = new Actions(obj1);
act1.moveToElement(obj2).perform();
act1.moveToElement(obj2).moveToElement(obj2.findElement(By.xpath("//*[@id='nav-flyout-ya-signin']/a/span"))).click().build().perform();
support: http://stackoverflow.com/questions/17293914/how-to-perform-mouseover-function-in-selenium-webdriver-using-java
Notes:
moveToElment() - Moves the mouse to an offset from the top-left corner of the element.
perform() - A convenience method for performing the actions without calling build() first.
build() - Generates a composite action containinig all actions so far, ready to be performed (and resets the internal builder state, so subsequent calls to build() will contain fresh sequences).
No comments:
Post a Comment