Switch Case for Dropdown Selection Issue
Hey all,
I'm working with a dropdown, where bladeParent is the category button, and bladeChild is a title within that category.
When you click bladeParent, then bladeChild will appear. If you click bladeParent again, it will close the dropdown. Pretty simple. In the case the dropdown is already open, you can click bladeChild right away and it will open the screen.
One thing I've noticed is that a common way for devs to hide elements on the screen is to make width and height 0.
so I came up with this method, and was working reliability until now. In the past I've had issues with .Exists and .VisibleOnScreen)
The issue: The very first time with a fresh browser session - the element navigate.bladeChild does not exist, and therefore has no width property yet, and then I get a prompt in my test saying "object doesn't exist" and fails.. it doesn't go to case false.
BUT if prior to test I click on the element once and and visually see it for a second, close the dropdown and then start my test, the routine runs perfectly everytime and it can go to either case true/false successfully with no issue at all.
My question is: Where is my logic wrong in this and what is the most robust/reliable solution for this scenerio? I know it's been asked a ton and I've tried many ways but there always seems to be a edge case and can't make it 100% reliable. Code is below. Many thanks community!
function NavBlade() {
Indicator.PushText("Navigating to Blade...");
let navigate = Aliases.browser.page.nav
let navbar = Aliases.browser.page.header
//Clear any open blades
Aliases.browser.page.header.button3.HoverMouse();
delay(200)
Aliases.browser.page.header.button3.Click();
delay(200)
//If bladeChild button is visible (not width=0) click it. If false then click bladeParent followed by the bladeChild button.
switch (!navigate.WaitAliasChild('bladeChild', 5000).Width == 0) {
case true:
Log.Message("case true width was not 0, click bladeChild")
delay(100);
navigate.bladeChild.HoverMouse();
delay(100);
navigate.bladeChild.Click();
Log.Checkpoint("Clicking bladeChild button...");
break
case false:
Log.Message("case false, width was 0")
delay(100);
navigate.bladeParent.HoverMouse();
delay(100);
navigate.bladeParent.Click();
delay(100);
navigate.bladeChild.HoverMouse();
delay(100);
navigate.bladeChild.Click();
Log.Checkpoint("Clicking bladeParent > bladeChild button...");
break;
}
}