July 8, 2013

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

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();
    }

}

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

14 comments:

  1. Good content presentation! Thanks for putting the efforts on gathering useful content and sharing here. You can find more Selenium testing related question and answers in the below forum.

    Selenium testing question and answers

    ReplyDelete
    Replies
    1. Hi i can not select the birth month.
      @driver.find_element(:xpath,"//span[@id='BirthMonth']/div/div[2]").click
      it's only click.but how can i select the a months from the selection box.plz guide me.

      Delete
    2. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Front end developer learn from Javascript Online Training from India . or learn thru ES6 Training in Chennai. Nowadays JavaScript has tons of job opportunities on various vertical industry. HTML5 CSS3 Javascript Online Training from India

      Delete

  2. Awesome post
    This is such a great resource that you are providing and you give it away for free. I love seeing websites that understand the value of providing a quality resource for free. It?s the old what goes around comes around routine. Did you acquired lots of links and I see lots of trackbacks??

    Big data online training

    ReplyDelete
  3. Hii.... I put same code... but not working... Pls help me. i am beginner in selenium.

    ReplyDelete
  4. It's not working at all.... Pls update the code to select the respected month correctly

    ReplyDelete
  5. driver.findElement(By.xpath(".//*[@id='BirthMonth']/div[1]")).sendKeys("Jan");

    ReplyDelete
  6. hi srikanth,

    it is list box how can u send the keys.its not work,sendkeys only Used for Text-Box.

    ReplyDelete
  7. Thanks alot for this coding and specially for SRIKANTH for month.
    For Gender its working
    driver.FindElement(By.XPath(".//*[@id='Gender']/div[1]")).SendKeys("Male");

    ReplyDelete
  8. Thanks for the .sendKeys advice. Realy helps)

    ReplyDelete
  9. Thanks for sharing the useful information and for the further information visit

    Oracle Fusion Financials Training

    ReplyDelete
  10. Hi i'm beginner in ruby can you please help me. how can i select the month from the gmail account.

    ReplyDelete
  11. This code is copied from another website

    ReplyDelete