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();
}
}
=============================================================
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();
}
}
=============================================================
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.
ReplyDeleteSelenium testing question and answers
Hi i can not select the birth month.
Delete@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.
ReplyDeleteAwesome 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
Hii.... I put same code... but not working... Pls help me. i am beginner in selenium.
ReplyDeleteIt's not working at all.... Pls update the code to select the respected month correctly
ReplyDeletedriver.findElement(By.xpath(".//*[@id='BirthMonth']/div[1]")).sendKeys("Jan");
ReplyDeletehi srikanth,
ReplyDeleteit is list box how can u send the keys.its not work,sendkeys only Used for Text-Box.
sorry its working
ReplyDeleteThanks alot for this coding and specially for SRIKANTH for month.
ReplyDeleteFor Gender its working
driver.FindElement(By.XPath(".//*[@id='Gender']/div[1]")).SendKeys("Male");
Thanks for the .sendKeys advice. Realy helps)
ReplyDeleteThanks for sharing the useful information and for the further information visit
ReplyDeleteOracle Fusion Financials Training
Hi i'm beginner in ruby can you please help me. how can i select the month from the gmail account.
ReplyDeleteThis code is copied from another website
ReplyDelete