Below is the Sample script to select
month from Gmail Registration page
Below is the image of Birth Month
Below is the image of Birth Month
The Birth Month field is not a Drop
down. By using normal select option we cannot 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.
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.
package
Others;
import
org.openqa.selenium.By;
import
org.openqa.selenium.WebDriver;
import
org.openqa.selenium.chrome.ChromeDriver;
import
org.testng.annotations.AfterClass;
import
org.testng.annotations.BeforeClass;
import
org.testng.annotations.Test;
public class
dropdown {
    public
WebDriver driver;
    @Test
    public void
testSelectBirthMonth() {        
            driver.findElement(By.id("FirstName")).sendKeys("Selenium");
        driver.findElement(By.id("LastName")).sendKeys("Webdriver");
        driver.findElement(By.id("GmailAddress")).sendKeys("seleniumwebdriverxyz");
        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("1999");       
    }
    @BeforeClass
    public void
beforeClass() throws Exception {                                                   
            System.setProperty("webdriver.chrome.driver", "D:\\Softwares\\chromedriver_win32\\chromedriver.exe");    
                        driver = new
ChromeDriver();
        driver.get("https://accounts.google.com/SignUp");        
    }
    @AfterClass
    public void
afterClass() {
        driver.quit();
    }
}
 
No comments:
Post a Comment