How to interact with "div" dropdown menu?

5,190 views
Skip to first unread message

Arya

unread,
Apr 5, 2012, 1:17:30 PM4/5/12
to Selenium Users
Hello

There are two drop down menus in the Google registration page Month
and Gender. It looks like they are made with div tags. Is there anyway
to select the month using WebDriver? I tried various things such as
using the keystrokes and sending clicks, I was able to open the list
of months and never able to select a month. Is there anyway to do
this? Here is the link to the page
https://accounts.google.com/SignUp?service=mail&continue=https%3A%2F%2Fmail.google.com%2Fmail%2F&ltmpl=default&hl=en


Best Regards!

Mike Riley

unread,
Apr 5, 2012, 2:06:33 PM4/5/12
to seleniu...@googlegroups.com
This is a fake dropdown, so using the Select class and its methods will not work here.

Here you will need to click on the proper div tag to cause the list to appear, but your div tags are not set up for that very well, since they only have classes defined and I will bet you have more than one div with those classes...

This one might work:
<div class="goog-inline-block goog-flat-menu-button-caption">Month</div>

You could use this XPath: "//div[text()=' Month ']" (note that spaces inside the quotes)

If you have another div with the same text you might have to qualify it with the class as well.

So doing a click on that will get the list to display, but you will need to wait until the div tag you wish to select becomes visible before clicking on it.  If you try to click on it while it is still hidden you will get an error.

Mike

Arya

unread,
Apr 5, 2012, 6:55:51 PM4/5/12
to Selenium Users
Thanks for the reply Mike

I'm able to get the list appear with the following code

driver.FindElement(By.XPath("//html/body/div/div[2]/div[2]/div/div/
form/div[5]/fieldset/label/span/div")).Click();

but I can't get it to click on any of the months.

Is there anyway to change "Month" in <div class="goog-inline-block
goog-flat-menu-button-caption">Month</div> to say March using another
method?
> >https://accounts.google.com/SignUp?service=mail&continue=https%3A%2F%...
>
> > Best Regards!

Arya

unread,
Apr 5, 2012, 7:09:33 PM4/5/12
to Selenium Users
ok I got it to work :)

This is what was needed to select the November

driver.FindElement(By.XPath("//html/body/div/div[2]/div[2]/div/div/
form/div[5]/fieldset/label/span/div[2]/div[11]/div")).Click();

NewUser

unread,
Apr 6, 2012, 12:19:05 AM4/6/12
to Selenium Users
Hi Arya

I was also facing the same problem. With your input I tried to do a
click and it throws an error that the element was not found. I am
using selenium rc. This is what I gave:

selenium.click("//div/div[2]/div[2]/div/div/form/div[5]/fieldset/label/
span/div/div[6]"); for selecting June. When I view this path in xpath
checker, I am able to see June. When I use this in my code, I get an
error.

Is there a way to achieve this?

Thanks

Arya

unread,
Apr 6, 2012, 1:39:05 PM4/6/12
to Selenium Users
I'm using Selenium2(Webdriver) try that bro. Also do you have AIM,
MSN, Skype?

On Apr 6, 12:19 am, NewUser <schalasani2...@gmail.com> wrote:
> Hi Arya
>
> I was also facing the same problem. With your input I tried to do a
> click and it throws an error that the element was not found. I am
> using selenium rc. This is what I gave:
>
> selenium.click("//div/div[2]/div[2]/div/div/form/div[5]/fieldset/label/
> span/div/div[6]"); for selecting June. When I view this path in xpath
> checker, I am able to see June. When I use this in my code, I get an
> error.
>
> Is there a way to achieve this?
>
> Thanks
>
> On Apr 6, 4:09 am, Arya <arya6...@gmail.com> wrote:
>
>
>
>
>
>
>
> > ok I got it to work :)
>
> > This is what was needed to select the November
>
> > driver.FindElement(By.XPath("//html/body/div/div[2]/div[2]/div/div/
> > form/div[5]/fieldset/label/span/div[2]/div[11]/div")).Click();
>
> > On Apr 5, 6:55 pm, Arya <arya6...@gmail.com> wrote:
>
> > > Thanks for the reply Mike
>
> > > I'm able to get the list appear with the following code
>
> > > driver.FindElement(By.XPath("//html/body/div/div[2]/div[2]/div/div/
> > > form/div[5]/fieldset/label/span/div")).Click();
>
> > > but I can't get it to click on any of the months.
>
> > > Is there anyway to change "Month" in <divclass="goog-inline-block
> > > goog-flat-menu-button-caption">Month</div> to say March using another
> > > method?
>
> > > On Apr 5, 2:06 pm, Mike Riley <lvskip...@cox.net> wrote:
>
> > > > This is a fakedropdown, so using the Select class and its methods will not
> > > > work here.
>
> > > > Here you will need to click on the properdivtag to cause the list to
> > > > appear, but yourdivtags are not set up for that very well, since they
> > > > only have classes defined and I will bet you have more than onedivwith
> > > > those classes...
>
> > > > This one might work:
> > > > <divclass="goog-inline-block goog-flat-menu-button-caption">Month</div>
>
> > > > You could use this XPath: "//div[text()=' Month ']" (note that spaces
> > > > inside the quotes)
>
> > > > If you have anotherdivwith the same text you might have to qualify it
> > > > with the class as well.
>
> > > > So doing a click on that will get the list to display, but you will need to
> > > > wait until thedivtag you wish to select becomes visible before clicking
> > > > on it.  If you try to click on it while it is still hidden you will get an
> > > > error.
>
> > > > Mike
>
> > > > On Thursday, April 5, 2012 10:17:30 AM UTC-7, Arya wrote:
>
> > > > > Hello
>
> > > > > There are two drop down menus in the Google registration page Month
> > > > > and Gender. It looks like they are made withdivtags. Is there anyway

chirag mittal

unread,
Jun 16, 2014, 8:35:16 AM6/16/14
to seleniu...@googlegroups.com
Hi Arya,

Facing the same issue but m not able to even open the list of months so can u plz help me on this..m using xpath

Gau Mun

unread,
Jun 17, 2014, 5:13:15 AM6/17/14
to seleniu...@googlegroups.com
You must have use the Action Class.

ClickAndHold then click to the Element.

take a look in the example : Action Class

THRINATH

unread,
Jun 18, 2014, 9:14:10 AM6/18/14
to seleniu...@googlegroups.com
Try, this must work!

      driver = new FirefoxDriver();
      driver.get("https://accounts.google.com/SignUp?continue=http%3A%2F%2Fwww.google.co.in%2F&hl=en");
      driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
      Actions action = new Actions(driver);
      action.clickAndHold(driver.findElement(By.id("BirthMonth"))).build().perform();
      driver.findElement(By.id(":2")).click();

Thrinath


--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/36c67993-8234-425d-ad00-23ea268bdf0a%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Regards,
Thirnath

tarun kumar

unread,
Sep 27, 2014, 3:36:15 PM9/27/14
to seleniu...@googlegroups.com
Hello Arya,

I have the same kind of issue that on the register page of application, we have a Month drop down,
I am able to get the list appear with the following code
wed.findElement(By.xpath("//*[@id='login_info']/table[1]/tbody/tr/td[2]/table/tbody/tr[2]/td/table/tbody/tr/td[1]/div[3]")).click();
but not able to select the month by using send key method with the above xpath.

but I am able to select the month by using below xpath
wed.findElement(By.xpath("//*[@id='month_menu']/li[4]/a")).click();

But I want to pass the month name from the excel

can you tell me how this issues get resolved

Note - it is a hidden drop down

if you want to see the application- URL = http://test.jiatro.com/mhs/index
click on the register link or join now button from the home page

Thanks,
Tarun

Abhay Rai

unread,
Sep 28, 2014, 10:53:27 AM9/28/14
to seleniu...@googlegroups.com
Hello Arya,
                      For this issue first find all element in the drop down and fetch the text and match the text provided by you in excel.
One you find the text read the index based on that index click the drop down item.
For example:
Precondition:  You have already click the drop down.                                            
Now get the all element by:
List<WebElement>  alldropdownitems=driver.findElements(By.xpath("//*[@id='month_menu']/li"));
// Now get the Size
int size=alldropdownitems.size or length

//Iterate through loop


For(int i=1;i<=size;i++)
{
String sMonthText=driver.findElement(by.xpath("//*[@id='month_menu']/li['"+i+"']")).getText();
if(sMonthText.eualsandignorecase(ExcelData))
{
//click the element
driver.findElement(by.xpath("//*[@id='month_menu']/li['"+i+"']")).click();
break;

Xiang Dong

unread,
Sep 28, 2014, 9:48:34 PM9/28/14
to seleniu...@googlegroups.com
Hi Tarun,

Ur application works like below,  using year as an example:

1. Click year drop down icon
2. Select year from drop down menu
3. Trigger javascript function changeYear()
4. in the javascript function, it modify the textContent of displayed year element (id = year_name) and set the selected year to the value of an hidden element(id=year)

So, based on above analysis, you can use javascript in web driver to set text to the displayed element and set value to the hidden element. It is a little complicated. The best way is figure out the relationship between month in ur excel and drop down menu, then click correct drop down menu option.

Hope it help you.
--david 


Date: Sat, 27 Sep 2014 12:36:15 -0700
From: replyt...@gmail.com
To: seleniu...@googlegroups.com
Subject: [selenium-users] Re: How to interact with "div" dropdown menu?
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages