Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's a suggestion for how <strong>access these elements in Selenium</strong>, with a Java example. </p> <p>It gets a little messy with <a href="http://www.w3.org/TR/CSS2/selector.html" rel="nofollow noreferrer">CSS Selectors</a> (which I generally prefer) because this month field has some fancy widgets on it to help hide your choices for security reasons. So here we go with XPath as our selector mechanism. </p> <p><em>Take notice I broke it down - 1st by selecting the month, and 2nd by selecting the month itself. Hope that helps.</em></p> <pre class="lang-java prettyprint-override"><code> public class Google Month Example { public static void main(String[] args) throws Exception { // Just picked Firefox for this example FirefoxDriver driver; driver = new FirefoxDriver(); driver.manage().timeouts().implicitlyWait(7, TimeUnit.SECONDS); // Head to URL driver.get("https://accounts.google.com/SignUp"); // Get the first click on the month field to generate the listbox pop-up driver.findElement(By.xpath(".//*[@id='BirthMonth']/div")).click(); // This is ":a" because each item in this month list is assigned a hex value starting at an index of zero driver.findElement(By.xpath(".//*[@id=':a']/div")).click(); // Check to see if November got selected if (!driver.findElement(By.xpath(".//*[@id='BirthMonth']/div[1]")).getText().equals("November")) { driver.close(); throw new RuntimeException("assertText 'November' failed"); } // Close browser window driver.quit(); } } </code></pre> <p><strong>Update: I realized you wanted to pass in the <code>Month</code> as an argument.</strong></p> <p>So swap out from the example above:</p> <pre class="lang-java prettyprint-override"><code>driver.findElement(By.xpath(".//*[@id=':a']/div")).click(); </code></pre> <p>for the below code:</p> <pre class="lang-java prettyprint-override"><code>String month = "November"; driver.findElement(By .xpath("//div[@class='goog-menuitem']/div[.='" + month + "']")).click(); </code></pre> <p><strong>Second Update:</strong></p> <p>So at one point you saw the HTML as:</p> <pre class="lang-xml prettyprint-override"><code>&lt;select id="BirthMonth" name="BirthMonth"&gt; &lt;option value=""&gt;Month&lt;/option&gt; &lt;option value="01" &gt;January&lt;/option&gt; &lt;option value="02" &gt;February&lt;/option&gt; ...... &lt;option value="12" &gt;December&lt;/option&gt; &lt;/select&gt; </code></pre> <p>But as I look at it in Chrome Dev Tools right now (pressing F12) after clicking on the <code>Month</code> field I see multiple small structure changes (posted what I see in the of the <a href="https://gist.github.com/anonymous/7680979" rel="nofollow noreferrer">Gist link</a>).Examples include <code>select</code> now becoming <code>span</code> and <code>value="01"</code> now shown as <code>id=":0"</code> (<a href="https://softwareengineering.stackexchange.com/questions/110804/why-are-zero-based-arrays-the-norm">Why the counting starts at zero and not 1</a>). Hope that explains some of why my example is different.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload