I always try to avoid using JavascriptExecutor. This feels like you are coupling the test to the implementation. If you ever want to refactor the code it could break your test. One idea behind test automation is that I can refactor my code and use the unchanged test automation to confirm the test still passes.
To select the month on a Gmail account creation I would do the following:
- select the link to create a new account
- click the Month selector to make the list of months appear
- wait for the month I want to select to be visible
- select the month
The code in Java would be:
// select the link to create a new account
driver.findElement(By.cssSelector("#link-signup")).click();
// click the Month selector to make the list of months appear
WebElement monthSelector = driver.findElement(By.cssSelector("#BirthMonth>div[title='Birthday']"));
driver.findElement(By.cssSelector("#BirthMonth>div[role='listbox']>div[id=':0']")).click();
// wait for the month I want to select to be visible
By monthLocator = By.xpath("//div[text()='December']");
wdw.until(ExpectedConditions.visibilityOfElementLocated(monthLocator));
// select the month
driver.findElement(monthLocator).click();
Notice that I broke the test down in comments. Once I had all the steps clearly listed it was a simple matter of converting the English comments to Selenium calls. I can do a similar thing with selecting the gender and location. I would actually code it as:
selectMonth("December");
selectGender("Male");
selectLocation("Canada");
then put the code to do each in methods.