Like us on Facebook

LightBlog

July 8, 2013

Select Month from Birthday field in Gmail registration page (New UI)

July 08, 2013 14
Below is the Sample script to select month from Gmail Registration page

Below is the image of Birth Month


The Birth Month field is not a Drop down. By using normal select option we can not select a value from that drop down. To select value from these kind of fields. We need to use click command.

Here in the below example..first click on the drop down arrow then all the elements (Month options) will be visible and then click on the option which you want to select.

Below is the sample code


==========================================================
package google;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

public class gmailReg_birthdaySelect {
    public WebDriver driver;

    @Test
    public void testSelectBirthMonth() {
    }
    @BeforeClass
    public void beforeClass() throws Exception {
        driver = new FirefoxDriver();
        driver.get("https://accounts.google.com/SignUp");

        driver.findElement(By.id("FirstName")).sendKeys("Selenium");
        driver.findElement(By.id("LastName")).sendKeys("Webdriver");
        driver.findElement(By.id("GmailAddress")).sendKeys("seleniumwebdriver");
        driver.findElement(By.id("Passwd")).sendKeys("testingnow");
        driver.findElement(By.id("PasswdAgain")).sendKeys("testingnow");
        //Click on the Arrow mark
        driver.findElement(By.xpath("//label[@id='month-label']/span/div/div")).click();
        //Select value from the list
        driver.findElement(By.xpath("//label[@id='month-label']/span/div[2]/div[@id=':5']")).click();
        driver.findElement(By.id("BirthDay")).sendKeys("16");
        driver.findElement(By.id("BirthYear")).sendKeys("1978");
        driver.findElement(By.xpath("//div[@id='Gender']/div/div")).sendKeys("Male");

    }

    @AfterClass
    public void afterClass() {
        // driver.quit();
    }

}

=============================================================