I have an link in HTML and I use Page Object pattern to write scripts with Selenium. But I can’t perform MouseMove action when object is initialized with pageFactory.
So, I have such class:
class BingPage
{
private readonly IWebDriver driver;
public static readonly String BASE_URL = "http://bing.com/";
[FindsBy(How = How.XPath, Using = ".//*[@id='scpt2']/a[text()='Shopping']")]
private IWebElement ShoopingLink;
public BingPage(IWebDriver driver)
{
this.driver = driver;
//Page Factory will use Driver to init searchButton and queryEdit objects
PageFactory.InitElements(driver, this);
}
public void HoverShoppingLink()
{
Actions builder = new Actions(driver);
IWebElement elem = driver.FindElement(By.XPath(".//*[@id='scpt2']/a[text()='Shopping']"));
builder.MoveToElement(elem).Build().Perform();//This will work
builder.MoveToElement(ShoopingLink).Build().Perform(); //This will fail
}
}
Line marked with comment “This will fail” will throw an exception “Must provide a location for a move action. Parameter name: actionTarget”
But when I manually lookup element – it works.
Could someone tell me why?
It is selenium 2.0 for .Net, .Net 4.0 with IE driver.
Because the proxy object (
ProxiedWebElementInterceptor) created for the element doesn’t proxyILocatable, which is what theActionsclass requires of its methods. This is a bug in the .NET bindings. It has been fixed in the current sources, and will be available in the next public release (2.21), available soon.