- Use the Actions class
- Hijack the mouse
- Execute Javascript
Example
[C#] Solution 1 : Action class
[C#] Solution 2 : Hijack the mouse
[C#] Solution 3 : Execute Javascript
Reference:
Actions
Provides a mechanism for building advanced interactions with the browser.
ExecuteScript
Executes JavaScript in the context of the currently selected frame or window.
IJavaScriptExecutor
Defines the interface through which the user can execute JavaScript.
ILocatable
Defines the interface through which the user can discover where an element is on the screen.
IMouse
Provides methods representing basic mouse actions.
MouseMove(ICoordinates)
Moves the mouse to the specified set of coordinates.
MoveToElement(IWebElement)
Moves the mouse to the specified element.
Hello world
[C#] Solution 1 : Action class
[Test]
public void handlingMouseoverEvent()
{
driver.Navigate().GoToUrl("http://testautomationengineer.blogspot.com/2013/12/selenium-webdriver-handling-mouseover.html");
Actions builder = new Actions(driver);
IWebElement smiley = driver.FindElement(By.Id("hoverOverMe"));
builder.MoveToElement(smiley).Build().Perform();
}
[C#] Solution 2 : Hijack the mouse
[Test]
public void handlingMouseoverEvent()
{
driver.Navigate().GoToUrl("http://testautomationengineer.blogspot.com/2013/12/selenium-webdriver-handling-mouseover.html");
ILocatable hoverItem = (ILocatable) driver.FindElement(By.Id("hoverOverMe"));
IMouse mouse = ((IHasInputDevices) driver).Mouse;
mouse.MouseMove(hoverItem.Coordinates);
}
[C#] Solution 3 : Execute Javascript
[Test]
public void handlingMouseoverEvent()
{
driver.Navigate().GoToUrl("http://testautomationengineer.blogspot.com/2013/12/selenium-webdriver-handling-mouseover.html");
var js = (IJavaScriptExecutor)driver;
js.ExecuteScript("$('[id=hoverOverMe]').trigger('mouseover')");
}
Reference:
Actions
Provides a mechanism for building advanced interactions with the browser.
ExecuteScript
Executes JavaScript in the context of the currently selected frame or window.
IJavaScriptExecutor
Defines the interface through which the user can execute JavaScript.
Defines the interface through which the user can discover where an element is on the screen.
IMouse
Provides methods representing basic mouse actions.
MouseMove(ICoordinates)
Moves the mouse to the specified set of coordinates.
MoveToElement(IWebElement)
Moves the mouse to the specified element.
No comments:
Post a Comment