Re: [webdriver] Identify Sidebar Menu Items and the inner menus

1,485 views
Skip to first unread message

Richard Lavoie

unread,
Oct 22, 2012, 5:30:32 PM10/22/12
to webd...@googlegroups.com
Screenshots are cool but worthless if you want someone to help you to get the right selectors to find your items in the menu.

You actually need to provide the HTML of the page for someone to help/give you hints on the retrieval of your menu items.

Richard



On 2012-10-22, at 13:30, Sumukh Bharadwaj <sumukhrb...@gmail.com> wrote:

Hi .. I am new to Selenium automation testing .. and have a query .. I need to identify the contents of a sidebar menu and the sub-menu for each. And then based on condition click on a particular Sub-menu.

Ex: I have attached a sample screen cap where in I need to identify the Mobiles & Accessories menu and then identify the sub-menu option and click it based on certain conditions.

Note: I am using IE for testing this application.

--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To view this discussion on the web visit https://groups.google.com/d/msg/webdriver/-/ra0vIBHae7UJ.
To post to this group, send email to webd...@googlegroups.com.
To unsubscribe from this group, send email to webdriver+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/webdriver?hl=en.
<Menu & Sub-menu items.jpg>

Sumukh Bharadwaj

unread,
Oct 23, 2012, 12:26:49 PM10/23/12
to webd...@googlegroups.com
Here is the HTML part of the content I was talking above

<ul class="fk-mh-navmenu">
<li id="fk-header-tab-mens-clothing" class="menuLink">
<li id="fk-header-tab-mobile" class="menuLink">
<div class="">
<div class="subMenu mobile hidden" style="display: none; left: 189px; top: -1px; z-index: 9999; background-position: left -579px;">
<div class="fk-mh-submenu-dsection left">
<div class="line fk-mh-navChild-content">
<div class="line fk-mh-navChild-Section">
<ul class="line fk-mh-navChild special">
<li class="fk-mh-navChild-item">
<a class="fk-mh-navChild-link " href="/phones?_pop=flyout">Phones Home</a>
</li>
<li class="fk-mh-navChild-item">
<a class="fk-mh-navChild-link " href="/mobiles?_pop=flyout">Mobiles Home</a>
</li>
<li class="fk-mh-navChild-item">
<a class="fk-mh-navChild-link " href="/mobiles/landline-phone-20347?_pop=flyout">Landline Phones</a>
</li>
<li class="fk-mh-navChild-item">
<a class="fk-mh-navChild-link " href="/mobile-accessories?_pop=flyout">Mobile Accessories Home</a>
</li>
<li class="fk-mh-navChild-item">
<a class="fk-mh-navChild-link " href="/mobiles/tablet-20278?_pop=flyout">Tablets</a>
</li>

So basically as per above class=fk-mh-navmenu corresponds to the layout with all the Main Menu options like Clothing, Mobiles and Acc etc .. and inside this we have child consisting of sub-menu options like Phones Home, Mobiles home etc ..

So I need to identify the sub-menu based on some conditions and open it (click the hyperlink).

I tried an approach by identifying the layout "fk-mh-navmenu" using the "className" method ..  but got an error ..

(WARNING: The server did not provide any stacktrace information)

Mike Riley

unread,
Oct 23, 2012, 3:25:39 PM10/23/12
to webd...@googlegroups.com
So you need to find the menu item you need to hover over.  It looks like each one has its own class, so you can find it by that class name using By.css().

You do the hover using the moveTo method of the Actions class.  Something like this:
WebElement = driver.findElement(By.css("whatever"));
Actions userAction = new Actions(driver);
userAction.moveToElement(element).perform();

You then need to wait for the element you wish to click on to become visible.  Once it is visible you can click on it.

You can probably use By.linkText() to find your various link elements.

Mike

Sumukh Bharadwaj

unread,
Oct 25, 2012, 1:30:12 PM10/25/12
to webd...@googlegroups.com
Hi Mike ..

Thanks for the quick reply .. your solution is working and I am able to identify the Main Menu item and traverse thru the sub menus.

I have a question though .. the code that I have written is working correctly in Firefox .. where as I keep getting error messages like

(WARNING: The server did not provide any stacktrace information) or getting redirected to wrong screens when I try the same thing on IE.

The code used looks something like this

WebElement element1 = driver.findElement(By.xpath(identifiervalue));

Actions userAction = new Actions(driver);
userAction.moveToElement(element1).perform();
WebElement element2 = driver.findElement(By.linkText("TEXT"));
element2.click();

Any idea what might be the issue here ..

Mike Riley

unread,
Nov 2, 2012, 3:39:11 PM11/2/12
to webd...@googlegroups.com
I use a routine in my library to wait for the element to become visible after I do the hover.  IE tends to be slower (than anything else out there, actually), so I am guessing that it is you findElement() that is having the problem here.  I am just not sure.

You do get a stack trace for your code.  So can you verify which line it is that is having the problem in IE?

Mike
Reply all
Reply to author
Forward
0 new messages