0

I am having some trouble selecting a hidden menu item on a work webpage using SeleniumBasic for vba. I have tried to use WebDriver.Mouse.MouseTo to hover over each menu option so that I can select the object nested "beneath" it, but after the first hover the object cannot be found.

In the picture below I intend to navigate like this:

Pricing Admin
    System Admin
        Multi-PAG Upload

picture

To do this, I have to hover over Pricing Admin and subsequently hover over System Admin so that menu appears to click on Multi-PAG Upload. I have successfully gotten the driver to hover over Pricing Admin which brings up first menu list with three items ending in System Admin. However, trying to FindElement() for System Admin so that I can hover on it has proven very difficult.

I tend get an object required error or an XPath selector invalid depending on the method that I attempt. I start having problems at Set systemAdmin =.

Any advice would be welcome!

Public Sub SeleniumTest()

    Dim driver As New WebDriver

    'open chrome to site
    driver.start "chrome"
    driver.Get "http://www.website.net"

    'login
    driver.FindElementByName("j_username").SendKeys ("user")
    driver.FindElementByName("j_password").SendKeys ("pass")
    driver.FindElementById("submit_button").Click


    'hover over Pricing Admin
    Dim pricingAdmin As WebElement
    Set pricingAdmin = driver.FindElementById("prcngAdmMnuFrm:prcngAdmMnu")

    driver.Mouse.MoveTo pricingAdmin


    Dim systemAdmin As WebElement
    'neither selection method below works properly
'   Set systemAdmin = driver.FindElementByXPath("//*[contains(text(),'System Admin')]")
'   Set systemAdmin = driver.FindElementByXPath("//div[@id='prcngAdmMnuFrm:prcngAdmMnu']/div/div/ul/li/ul/li[3]/ul/li[4]/a/span/span")

    driver.Mouse.MoveTo systemAdmin


    Dim multiPagUpload As WebElement
'   Set multiPagUpload = driver.FindElement("??")

    multiPagUpload.Click


    'closes browser window
    driver.Quit

End Sub

Here is the (abridged) HTML for the site. I trimmed out a bit of the lists for simplicity's sake but if it's actually necessary (for using javascript, etc) let me know and I can pop more in.

<div id="prcngAdmMnuFrm:prcngAdmMnu" style="">
    <div class="ui-widget ui-widget-content wijmo-wijmenu ui-corner-all ui-helper-clearfix wijmo-wijmenu-horizontal" aria-activedescendant="ui-active-menuitem" role="menubar">
        <div class="scrollcontainer checkablesupport">
            <ul style="display: block;" class="wijmo-wijmenu-list ui-helper-reset" tabindex="0">
                <li role="menuitem" class="ui-widget wijmo-wijmenu-item ui-state-default ui-corner-all wijmo-wijmenu-parent" aria-haspopup="true" style="">
                    <a href="#" class="wijmo-wijmenu-link ui-corner-all" id="">
                        <span class="wijmo-wijmenu-text">
                            <span class="wijmo-wijmenu-text">Pricing Admin</span>
                        </span>
                        <span class="ui-icon ui-icon-triangle-1-s"></span>
                    </a>
                    <ul class="wijmo-wijmenu-list ui-widget-content ui-corner-all ui-helper-clearfix wijmo-wijmenu-child" style="display: none; left: 0px; top: 38px; position: absolute; list-style-type: none;" aria-hidden="true">
                        <li role="menuitem" class="ui-widget wijmo-wijmenu-item ui-state-default ui-corner-all wijmo-wijmenu-parent" aria-haspopup="true" style="">
                            <a href="#" class="wijmo-wijmenu-link ui-corner-all ui-state-focus">
                                <span class="wijmo-wijmenu-text">
                                    <span class="wijmo-wijmenu-text">System Admin</span>
                                </span>
                                <span class="ui-icon ui-icon-triangle-1-e"></span>
                            </a>
                            <ul class="wijmo-wijmenu-list ui-widget-content ui-corner-all ui-helper-clearfix wijmo-wijmenu-child" style="display: none; left: 215px; top: -1px; position: absolute; list-style-type: none;" aria-hidden="true">
                                <li role="menuitem" class="ui-widget wijmo-wijmenu-item ui-state-default ui-corner-all">
                                    <a onclick="showProcessingMessage('Loading');;var self = this; setTimeout(function() { var f = function(opt){ice.ace.ab(ice.ace.extendAjaxArgs({&quot;source&quot;:&quot;prcngAdmMnuFrm:menu_pad_sa_multi&quot;,&quot;execute&quot;:'@all',&quot;render&quot;:'@all',&quot;event&quot;:&quot;activate&quot;}, opt));}; f({node:self});}, 10);" style="cursor:pointer;" class="wijmo-wijmenu-link ui-corner-all">
                                        <span class="wijmo-wijmenu-text">
                                            <span class="wijmo-wijmenu-text">Multi-PAG Upload</span>
                                        </span>
                                    </a>
                                </li>
                            </ul>
                        </li>
                    </ul>
                </li>
            </ul>
        </div>
    </div>
    <script type="text/javascript">
        var widget_prcngAdmMnuFrm_prcngAdmMnu = ice.ace.create("Menubar", ["prcngAdmMnuFrm:prcngAdmMnu", {
            "autoSubmenuDisplay": true,
            "direction": "auto",
            "animation": {
                "animated": "fade",
                "duration": 400
            }
        }]);
    </script>
</div>

If I've left anything out that you need to troubleshoot, please let me know!

Marcucciboy2
  • 3,156
  • 3
  • 20
  • 38

1 Answers1

1

The xpath which is used in the code is not correct. my suggesting to find the anchor element and move the mouse over.

# System Admin Menu

'Hover over Pricing Admin
Dim systemAdmin As WebElement
Set systemAdmin = driver.FindElementByXPath("//a[.//span[contains(.,'System Admin')]]")

driver.Mouse.MoveTo pricingAdmin

If the mouse hover does not work, we can still try to handle the menu by clicking on the anchor element and then sendkeys (keys.Arrow_Right)

#Multi-PAG Upload

Dim multiPagUpload As WebElement
Set multiPagUpload = driver.FindElementByXPath("//a[.//span[contains(.,'Multi-PAG Upload')]]")

multiPagUpload.Click
Sureshmani Kalirajan
  • 1,938
  • 2
  • 9
  • 18
  • Unfortunately I still get `Run-time error '438': Object doesn't support this property or method` on the line `Set systemAdmin =` – Marcucciboy2 Aug 08 '19 at 16:37
  • @Marcucciboy2 sounds like a VBA issue. lets try directly use the element than assigning to a variable. driver.Mouse.MoveTo driver.FindElementByXPath("//a[.//span[contains(.,'System Admin')]]") – Sureshmani Kalirajan Aug 08 '19 at 16:56
  • 1
    Updated the code to remove duplicate "driver.driver". give it a try now – Sureshmani Kalirajan Aug 08 '19 at 17:00
  • Oh gosh, I can't believe I didn't proof it well enough to notice the extra `driver.` >_> – Marcucciboy2 Aug 08 '19 at 17:51
  • sorry, quick followup question - is it possible to adjust the selection for **multiPagUpload** to click specifically on the text link and not just another part of the ``? – Marcucciboy2 Aug 08 '19 at 18:11
  • 1
    The above xpath will click on the anchor part of the element,not the span. It identifies the anchor based on the text present on the child span element though. – Sureshmani Kalirajan Aug 08 '19 at 19:03