Trouble selecting a hidden menu item using SeleniumBasic for vba - vba

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
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({"source":"prcngAdmMnuFrm:menu_pad_sa_multi","execute":'#all',"render":'#all',"event":"activate"}, 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!

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

Related

Images for after clicking on suboption from the popup window remains as it is in selenium

In my application left-hand side menu bar which contain 8 modules of an application. And each of module contain suboptions.
I am trying to click on one of suboption from a particular module which having 30 suboptions(pages).
But after clicking on a particular option the popup window remains as it is on screen and it does not allow me to click the options which are behind the popup screen.
Behind popup screen the dropdown option is there and want to select one option from that dropdown.
Its giving me an error "org.openqa.selenium.JavascriptException: javascript error: Failed to execute 'elementsFromPoint' on 'Document': The provided double value is non-finite."
Here is the code
//div[#id='main-nav']/ul --Gives me 6 modules name(6 ul):
<ul class="main-nav-gray-border user-details-menu-tab left-nav-main-menu-container left-nav-img-ul" xpath="1"></ul>
<ul class="main-nav-gray-border menu-items-main-menu-list left-nav-main-menu-container left-nav-img-ul" xpath="2">
<li class="main-nav-img-label" id="admin-nav">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" class="main-nav-icons"></svg>
<label>
Analytics
</label>
<ul class="nav-items admin-menu-items" style="top: 50px;" id="admin-menu-items">
<li class="side-nav-titles"></li>
<a class="module-item-child selected-nav-item" href="#" id="QualityMeasures37" onclick="loadModule('Analytics/Index?dashboardUrlId=71', 2,'QualityMeasures', 37,null,'Quality Measures')" xpath="1">
<li>**Quality Measures**</li>
</a>
<a class="module-child " id="QualityMainView38" onclick="loadModule('Analytics/Index?dashboardUrlId=93', 2,'QualityMainView', 38,null,'Quality Main View')"></a>
<a class="module-child " id="QualityRanking39" onclick="loadModule('Analytics/Index?dashboardUrlId=94', 2,'QualityRanking', 39,null,'Quality Ranking')"></a>
<a class="module-child " id="QualityTrending40" onclick="loadModule('Analytics/Index?dashboardUrlId=95', 2,'QualityTrending', 40,null,'Quality Trending')"></a>
<a class="module-child user-default-module selected-nav-item" href="#" id="DetailedFinanceAndUtilization41" onclick="loadModule('Analytics/Index?dashboardUrlId=76', 2,'DetailedFinanceAndUtilization', 41,null,'Detailed Finance & Utilization')"></a>
<a class="module-child " id="DetailedFinanceandUtilizationPro42" onclick="loadModule('Analytics/Index?dashboardUrlId=77', 2,'DetailedFinanceandUtilizationPro', 42,null,'Detailed Finance & Utilization Professional')"></a>
<a class="module-child " id="PartAClaimsAnalysis43" onclick="loadModule('Analytics/Index?dashboardUrlId=87', 2,'PartAClaimsAnalysis', 43,null,'Facility Claims Analysis')"></a>
</ul>
</li>
</ul>
<ul class="main-nav-gray-border menu-items-main-menu-list left-nav-main-menu-container left-nav-img-ul" xpath="3"></ul>
<ul class="icon-minimizer" id="minimizer-nav" xpath="7"></ul>
This the code for a drop down menu.
<div class="dd-select" style="width: 100px; background: rgb(245, 245, 245);" xpath="1">
<input class="dd-selected-value" type="hidden" value="Level1"><a class="dd-selected"><label class="dd-selected-text" title="Enterprise">Enterprise</label></a>
<span class="dd-pointer dd-pointer-down"></span></div>
This is the code to select the option from drop down menu.
<div id="SelectedHierarchyLevelName" class="dd-container" style="width: 100px;" xpath="1">
<div class="dd-select" style="width: 100px; background: rgb(245, 245, 245);">
<input class="dd-selected-value" type="hidden" value="Level3">
<a class="dd-selected">
<label class="dd-selected-text" title="Facility">**Facility**</label></a>
<span class="dd-pointer dd-pointer-down dd-pointer-up"></span></div>
<ul class="dd-options dd-click-off-close" style="min-width: 100px; height: 150px; overflow: auto; box-shadow: rgba(0, 0, 0, 0.176) 0px 6px 16px; display: block;">
<li class=""><a class="dd-option"> <input class="dd-option-value" type="hidden" value="Level1"> <label class="dd-option-text">Enterprise</label></a></li>
<li class=""><a class="dd-option"> <input class="dd-option-value" type="hidden" value="Level2"> <label class="dd-option-text">Ministry</label></a></li>
<li class=""><a class="dd-option dd-option-selected"> <input class="dd-option-value" type="hidden" value="Level3"> <label class="dd-option-text">Facility</label></a></li>
<li class=""><a class="dd-option"> <input class="dd-option-value" type="hidden" value="Level4"> <label class="dd-option-text">Med Group/Division</label></a></li>
<li class="hideMe"><a class="dd-option"> <input class="dd-option-value" type="hidden" value="Missing Providers"> <label class="dd-option-text">Missing Providers</label></a></li>
<li class=""><a class="dd-option"> <input class="dd-option-value" type="hidden" value="Help"> <label class="dd-option-text">Help</label></a></li>
<li class="hideMe"><a class="dd-option"> <input class="dd-option-value" type="hidden" value="L0Simulation"> <label class="dd-option-text">Unknown Simulation</label></a></li></ul></div>
I tried following:
#FindBy(id="admin-nav")
WebElement mouseHover;
#FindBy(xpath="//a[#id='QualityMeasures37']//li[contains(text(),'Quality Measures')]")
WebElement btnQualityMeasure;
#FindBy(xpath="//div[#id='SelectedHierarchyLevelName']//span[#class='dd-pointer dd-pointer-down']")
WebElement dropDown;
#FindBy(xpath="//label[contains(text(),'Facility')]")
WebElement facilityOption;
public void hoverTest() throws Exception
{
Actions act = new Actions(driver);
act.moveToElement(mouseHover).build().perform();
Thread.sleep(2000);
// ((JavascriptExecutor)driver).executeScript("arguments[0].scrollIntoView(true);", btnQualityMeasure);
// Thread.sleep(1000);
act.moveToElement(btnQualityMeasure).click().build().perform(); //clicking on suboption
Thread.sleep(10500);
}
public void clickDropDownButton()
{
Actions act = new Actions(driver);
act.moveToElement(dropDown).click().build().perform();
}
public void selectFromDropDown() throws Exception{
Actions act1 = new Actions(driver);
// ((JavascriptExecutor)driver).executeScript("arguments[0].scrollIntoView(true);", ministryOption);
// Thread.sleep(1000);
act1.moveToElement(ministryOption).click().build().perform();
Thread.sleep(1500);
//The first method Mousehover it and select the desired suboption.
Second method clicking on dropdown button and 3rd method selecting the option from drop down.
In short from the 'Analytics' module the suboption 'Quality Measure' should be select and on that page click on one drop down menu and select the option 'Facility'. I highlighted as bold all 3 in my above code.
Its giving me an eroor "Its giving me an error "org.openqa.selenium.JavascriptException: javascript error: Failed to execute 'elementsFromPoint' on 'Document': The provided double value is non-finite."
Also some time it does not open the desired suboption.
Any help will be appreciated.

How to expand jstree list items in the website using vbscript?

I need to automate some website with vbscript. In here as shown below have some jstree unordered list with list items.
<div id="categoryTree" class="category-treeview jstree jstree-1 jstree-default" role="tree" aria-activedescendant="cat35">
<ul class="jstree-container-ul jstree-children">
<li role="treeitem" aria-expanded="false" id="cat001" class="jstree-node jstree-closed">
<i class="jstree-icon jstree-ocl"></i>
<a class="jstree-anchor" href="#"><i class="jstree-icon jstree-themeicon jstree-themeicon-custom" style="background-image: url("abc/9174db8b-e42f-41c8-928d-a60c83f3e094.JPG"); background-position: center center; background-size: auto;"></i>A Web Services (AWS)</a>
</li>
<li role="treeitem" aria-expanded="false" id="cat002" class="jstree-node jstree-closed"></li>
<li role="treeitem" aria-expanded="false" id="cat003" class="jstree-node jstree-closed"></li>
</ul></div>
Ihave try to expand list item using below vbscript code snippet.
Set btnTreeListItem = IE.document.getElementById("cat001")
btnTreeListItem.Click
But It's nothing happen. So how to do that accordingly?
Thanks.
Regards.
Assuming it is the a tag that needs clicking then try using a css class selector to target that tag by className
ie.document.querySelector(".jstree-anchor").click

change class of glyphicon when nav-item is open

I am using bootstrap menu on a web page.
my menu list looks something like this:
<li><a class="nav-link dropdown-toggle" href="#" id="navbarDropdown"
role="button" data-toggle="dropdown" aria-haspopup="true" aria-
expanded="false">main item
<span class="pull-left glyph-btn-menu">
<em class="glyphicon glyphicon-menu-down"></em>
</span>
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
sub item1<br>
sub item2<br>
sub item2<br>
</div>
</li>
I want glyphicon symbol to change to class glyphicon-menu-up when nav-link is clicked and submenu items open and then again to change back to glyphicon-menu-down when nav-item is closed or when a different nav-item is clicked.
What would be the best way to acheive that
So this is my solution.
I gave the parent ul the an id value: id="theme"
bootstrap adds the class open to an open li so I check to see if any li have the class open, remove and add glyphicon classes as needed
$('#theme li').click(function () {
if($(this).hasClass('open')){
//alert('aaa');
$(this).children('a').children('span').children('em').removeClass('glyphicon-menu-up');
$(this).children('a').children('span').children('em').addClass('glyphicon-menu-down');
} else {
$(this).children('a').children('span').children('em').removeClass('glyphicon-menu-down');
$(this).children('a').children('span').children('em').addClass('glyphicon-menu-up');
}
});

Selenium - Not able to Click Dynamically Visible Menu

I have a Menu which have li
(list) elements which gets enabled after you mouse-hover a particular label.
driver.get("www.snapdeal.com"); Actions actions = new Actions(driver);
actions.moveToElement(driver.findElement(By.id("loggedOutAccount"))).build().perform();
//Wait for 5 Secs
driver.findElement(By.className("accountLink")).click();// Here it's throwing Element not visible exception
This code is doing the mouse-hover properly but not able to click the "SignIn Link" Link. Though on manually checking the element is Visible
DOM Structure -
<div id="loggedOutAccount" class="hd-rvmp-logout">
<a class="signIn" href="javascript:void(0);">
<i class="iconHeader accountUser"></i>
<label class="my-account-lang"> My Account</label>
<i class="mar_2_left right-downArrow breadcrumbArrow-down"></i>
</a>
<div class="sdNavDropWrapper accDetails" style="display: none; z-index: 999;">
<ul class="positionAbsolute pull-right">
<li class="customLoggedInState">
<div class="left triangle"></div>
<div class="right triangle"></div>
<div>
<a class="accountLink" href="javascript:void(0);">Click here to sign in ></a>
</div>
</li>
<li class="stop-event">
<li class="stop-event">
<li class="stop-event">
<li class="stop-event">
<li class="stop-event">
</ul>
</div>
</div>
Please use xpath for both element like below :
driver.get("www.snapdeal.com");
Actions actions = new Actions(driver);
actions.moveToElement(driver.findElement(By.xpath("yourxpathhere"))).build().perform();
driver.findElement(By.xpath("yourxpathhere")).click();
I think class/Id repeating for other elements also for style purpose. so Xpath is better to find unique element.

Beginner in UI Automation unable to locate a dropdown element. Dropdown is static & has only 3 options

HTML Code for the drop down with 3 constant values:
<div class="a-popover-inner" style="height: auto; overflow-y: auto; min-width: 107px; width: auto;">
<ul id="3_dropdown_combobox" class="a-nostyle a-list-link" aria-multiselectable="false" role="listbox" tabindex="-1">
<li class="a-dropdown-item status-option" role="option" tabindex="0">
<li class="a-dropdown-item status-option" role="option" tabindex="0">
<a class="a-dropdown-link a-active" data-value="{"stringVal":"Active"}" href="javascript:void(0)" tabindex="-1"> Active </a>
</li>
<li class="a-dropdown-item status-option" role="option" tabindex="0">
</ul>
Tried:
driver.findElement(By.xpath("//*[#id='status-select']/span/span"));
Result:
Able to click/select the dropdown successfully
But Unable to further select a specific dropdown
Try1:
driver.findElement(By.xpath("//*a[#data-value={'stringVal':'Active'}]")).click();
Result1:InvalidSelectorError: Unable to locate an element with the xpath expression
Try2:
java.util.List<WebElement> elements = driver.findElements(By.xpath("//*[#id='status-select']/span/span"));
Result3: count = element.size(); // prints count as 1
//so cant get elements[element.count-1];
Try3:
Select select = new Select(driver.findElement(By.id("3_dropdown_combobox")));
select.selectByVisibleText("Expired");
Result3:
Try4:
driver.findElement(By.xpath("//*[#id='3_dropdown_combobox']/li[2]/a")).click();
(or)
java.util.List<WebElement> elements = driver.findElements(By.id("3_dropdown_combobox"));elements.size();
Result4: console does nothing for >10min. I stop the execution
Please Guide me on what is correct way to select 2nd/3rd dropdown options
Do this:
Select select = new Select(driver.findElement(By.id("status-select")));
select.selectByIndex(1); //Selects the 2nd option in the dropdown list
In order to click the Active link this should work for you:
driver.findElement(By.xpath("//*[#id="3_dropdown_combobox"]/li[2]/a")).click();
I tried doing
driver.findElement(By.xpath("//*[#id="3_dropdown_combobox"]/li[2]/a")).getText();
and got the word Active as expected.
Try to see if the link takes you to the correct location