For the past two days, I've been struggling to find an effective method for writing integration tests for my ASP.NET website using Selenium.
The website features a Telerik RadMenu with a hierarchical structure like this:
Root Menu
- Menu 1
- Sub Menu 1.1
- Sub Menu 1.2
- Menu 2
- Sub Menu 2.1
- Menu 3
- Sub Menu 3.1
- Sub Menu 3.2
- Sub Menu 3.3
When a user hovers over the "Root menu", it opens a "Menu" and upon further hover, it opens a "Sub Menu". Clicking on the "Sub Menu" then triggers a Telerik dialog box.
I attempted various methods to execute two hovers and a click operation, such as:
Method 1:
Actions action = new Actions(Browser.Driver);
IWebElement we = Browser.Driver.FindElement(By.XPath("//*[@id='ctl00_ContentPlaceHolder1_RadMenu1']"));
action.MoveToElement(we).MoveToElement(we.FindElement(By.XPath("ul/li/div/ul/li[1]"))).Build().Perform();
action.MoveToElement(we.FindElement(By.XPath("ul/li/div/ul/li[1]/div/ul/li[1]"))).Click().Build().Perform();
Method 2:
var advFilter = Browser.Driver.FindElement(By.Id("ctl00_ContentPlaceHolder1_RadMenu1"));
Actions action = new Actions(Browser.Driver);
var advFiltersPrimary = Browser.Driver.FindElements(By.CssSelector(".rmLevel1>li"))[0];
action.MoveToElement(advFilter).MoveToElement(advFiltersPrimary).Build().Perform();
var advFiltersSec = Browser.Driver.FindElements(By.CssSelector(".rmLevel2>li"))[0];
action.MoveToElement(advFiltersSec).Click().Build().Perform();
The generated HTML structure of the RadMenu component is detailed above.
While Method 1 works sporadically and tends to fail during the execution of hovering at the "Sub Menu" level, Method 2 often selects the wrong element even when explicitly indicating the first element.
If you have any suggestions or better ways to approach this issue, your guidance would be greatly appreciated.