Unable to select text from dropdown - Gmail.com Month

85 views
Skip to first unread message

Selenium User

unread,
Apr 2, 2012, 8:41:40 PM4/2/12
to SeleniumWiki
Trying to select a month from a drop down in www.gmail.com
Able to identify element and perform a click evnet, but it is not
selecting a month from the drop down.


HTML Snippet from Firebug.
<div class="goog-inline-block goog-flat-menu-button jfk-select"
title="" role="listbox" style="-moz-user-select: none;" tabindex="0"
aria-haspopup="false" aria-expanded="false" aria-activedescendant="">
<div class="goog-inline-block goog-flat-menu-button-
caption">Month</
div>
<div class="goog-inline-block goog-flat-menu-button-
dropdown">&nbsp;</
div>
</div>
<input id="HiddenBirthMonth" type="hidden" name="BirthMonth"
value="09">
<div class="goog-menu goog-menu-vertical" style="-moz-user-select:
none; visibility: visible; left: 0px; top: -194.917px; display: none;"
role="menu" aria-haspopup="true" aria-activedescendant="">
<div id=":0" class="goog-menuitem" role="option" style="-moz-
user-
select: none;">
<div class="goog-menuitem-content">January</div>
</div>
<div id=":1" class="goog-menuitem" role="option" style="-moz-
user-
select: none;">
<div class="goog-menuitem-content">February</div>
</div>
<div id=":2" class="goog-menuitem" role="option" style="-moz-
user-
select: none;">
<div class="goog-menuitem-content">March</div>
</div>
</div>

on mouse over on the div it is changing the style and below div is
getting visible and listing the dropdown.


Java Code.
// XPath - //div[@class='goog-inline-block goog-flat-menu-button jfk-
select']
boolean boolMonthXPathExists = false;
//String strMonthXPathElementId = "//div[@class='goog-inline-block
goog-flat-menu-button jfk-select']";
String strMonthXPathElementId = "//div[@class='goog-inline-block goog-
flat-menu-button jfk-select']";
String strMonthXPathIdentifier = "xpath";
boolMonthXPathExists = checkElement(driver,
strMonthXPathElementId,strMonthXPathIdentifier);
if(boolMonthXPathExists) {
driver.findElement(By.xpath(strMonthXPathElementId)).click();
}

// Month - //div[@id=':1']
boolean boolMonthListExists = false;
String strMonthListElementId = "//div[@id=':1']";
String strMonthListIdentifier = "xpath";
boolMonthListExists = checkElement(driver,
strMonthListElementId,strMonthListIdentifier);
if(boolMonthListExists) {
driver.findElement(By.cssSelector(strMonthListElementId));
System.out.println("Element Identified boolMonthListExists -->
" +
boolMonthListExists);
}

// Month - //div[text()='January']
boolean boolMonthListTextExists = false;
String strMonthListTextElementId = "//div[text()='January']";
String strMonthListTextIdentifier = "xpath";
boolMonthListTextExists = checkElement(driver,
strMonthListTextElementId,strMonthListTextIdentifier);
if(boolMonthListTextExists) {
driver.findElement(By.cssSelector(strMonthListTextElementId));
System.out.println("Element Identified
strMonthListTextElementId -->
" + strMonthListTextElementId) ;
}


private static boolean checkElement(WebDriver driver, String
strElementId, String strIdentifier) {
boolean boolExists = false;
while(true) {
driver.manage().timeouts().implicitlyWait(0,
TimeUnit.MILLISECONDS);
driver.manage().timeouts().implicitlyWait(10,
TimeUnit.MILLISECONDS);

if("id".equalsIgnoreCase(strIdentifier)) {
boolExists =
driver.findElement(By.id(strElementId)).isDisplayed();
System.out.println("Element identified in id --
> " + boolExists);
} else if
("cssSelector".equalsIgnoreCase(strIdentifier)) {
boolExists =
driver.findElement(By.cssSelector(strElementId)).isDisplayed();
System.out.println("Element identified in
cssSelector --> " +
boolExists);
} else if ("xpath".equalsIgnoreCase(strIdentifier)) {
boolExists =
driver.findElement(By.xpath(strElementId)).isDisplayed();
System.out.println("Element identified in xpath
--> " +
boolExists);
}
if(boolExists) {
break;
}
}
return boolExists;
}


Console Error.

Caused by: org.openqa.selenium.remote.ErrorHandler
$UnknownServerException: The given selector //div[text()='January'] is
either invalid or does not result in a WebElement. The following error
occurred:

Please help to perform a click on the dropdown.
Reply all
Reply to author
Forward
0 new messages