Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
35
(Selenium WebDriver) Menu click pass but nothing happens on page
posted

I am writing a selenium C# test code for an old "infragistics" (I seriouly don't know too much about this) page. The page doesn't give me that much options when it comes to elements references. Like in the HTML below I want to click on INVENTORY which is a submenu of a menu item but there is no element Id or Name so I used XPath (see code below). It looks like webdriver recognizes that xpath but when the click function executes and complete, nothing happens on the page. It does not open the expected page. Is there something that I am doing wrong here?

Infragistic HTML:

<!-- begin snippet: js hide: false console: true babel: false -->

<li class="igdm_MenuItemVertical igdm_MenuItemVerticalParent " unselectable="on" data-ig="x:1171509256.11:adr:1.2" adr="1.2"><A onclick="{return false;}" tabIndex=-1 class="igdm_MenuItemVerticalLink " href="#/Inventory...">
<a onclick="{return false;}" tabIndex=-1 class="igdm_MenuItemVerticalLink>
<img class="igdm_MenuItemVerticalIcon " alt=" Inventory..." src="../Images/report16.gif">
<span tabIndex=-1 unselectable="on"> INVENTORY...</span>
</a>

<!-- end snippet -->

C# Code:

private By FileSubMenu = By.XPath(".//li/a/span[text()=' Inventory...']");

public HomePage SubMenu()
{
int retryCount = 0;
while (true && retryCount < Constants.RETRY_COUNT)
{
try
{
Thread.Sleep(3000);
IWebElement element = _driver.FindElement(FileSubMenu);
Actions Rmouseover = new Actions(_driver);
Rmouseover.MoveToElement(element).Click().Perform();
return this;
}
catch (Exception ex) when (ex is WebDriverTimeoutException || ex is TimeoutException)
{
retryCount++;
Thread.Sleep(3000);
}
}
return this;
}

  • 0
    Offline posted

    XPath is okay, but I prefer CSS Selector as it tends to yeild less brittle selectors (not so location in the DOM based, but still can be). To get one in Chrome:

    1. Right-click on the element and select 'Inspect'
    2. Right-click on the element in the DOM explorer of DevTools
    3. Select "Copy" > "Copy selector"

    So then your code would look something like:

    IWebElement element =  driver.FindElement(By.CssSelector("paste_the_selector_here"));
    // Click via Selenium's Click method
    element.Click();
    // Or, click via JavaScript
    ((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].click()", element);

    Also, instead of clicking the <span> you may want to click on the <a> instead as it has an onclick event listener.

    If the selector includes an ID for a parent that is dynamic, then you'll want to remove it. To remove it, find the element with that ID in the DevTool's Element tab. Double-click on the id="..." part and delete the whole thing. Now get the selector for the child element.

    This example

    <div id="ctl00_NavBarAdmin_WebDataMenu1"> // <- Parent div html
    #ctl00_NavBarAdmin_WebDataMenu1 > ul > li:nth-child(2) > ul > li.igdm_MenuItemVertical.igdm_MenuItemVerticalParent.igdm_Me‌​nuItemVerticalSelect‌​ed > a

    Might become

    <div> // <- Parent div HTML
    div > ul > li:nth-child(2) > ul > li.igdm_MenuItemVertical.igdm_MenuItemVerticalParent.igdm_Me‌​nuItemVerticalSelect‌​ed > a 
  • 11095
    Offline posted

    Hello,

    Please note that the version you are using is retired several years ago and understandably would not work with modern browsers that were released after the last volume of the classic controls, which was Infragistics NetAdvantage v11.1 of ASP.NET. The product lifecycle is stated in the following page:
    https://ko.infragistics.com/support/product-lifecycle.
    The only possible solution in this case is to use a product that is supported under newer browsers, which you can identify in the supported environments page at:
    https://ko.infragistics.com/support/supported-environments.
    So what you could do is to upgrade to the new ASP.NET Ajax tool-set. You can take a look at it at:
    https://ko.infragistics.com/products/aspnet.