title: Find elements inside forms and iframe using Java and Selenium WebDriver
body: <p>I'm trying to access elements that are present under <code>&lt;form&gt; &lt;iFrame&gt; &lt;form&gt; elements &lt;/form&gt; &lt;/iFrame&gt; &lt;/form&gt;</code>.</p>
  
  <p>Could you help me on accessing these <em>'elements'</em>, which I'm working with Selenium Webdriver and JAVA?</p>
  
  <p><strong>Issue Encountered:</strong> Able to reach the destination page (where the above elements are present), but those elements are not recognized with my code.</p>
  
  <p><strong>Overview of XML structure:</strong></p>
  
  <pre><code>&lt;body&gt;
      &lt;form action="https://abcd/efgh/" name="outerForm" method="post" target="iFrameTitle"&gt;
          &lt;iframe width="700" height="600" src="" title="Frame for Java Test" name="iFrameTitle" scrolling="auto" frameborder="0"&gt;
              &lt;form id="innerFormID" name="innerForm" action="/xxx/xxxx/yyyy/zzzz/" method="post" autocomplete="off"&gt;
                  &lt;fieldset id="ncDetailsInner"&gt;
                      &lt;div id="element1"&gt;
                          &lt;label for="label1"&gt;
                          &lt;abbr title="Required field"&gt;*&lt;/abbr&gt;&lt;/label&gt;
                          &lt;input name="label2" type="text" maxlength="30" id="cardHolder" value="" &gt;
                      &lt;/div&gt;
  
                      &lt;div id="element2"&gt;
                          &lt;label for="label3"&gt;Label3 &lt;abbr title="Required field"&gt;*&lt;/abbr&gt;&lt;/label&gt;
                          &lt;div id="element3"&gt;
                              &lt;label for="label4"&gt;Label4&lt;abbr title="Required field"&gt;*&lt;/abbr&gt;&lt;/label&gt;
                              &lt;input id="label5" name="labelname5" type="text" maxlength="19" value=""&gt;
                          &lt;/div&gt;
  
                          &lt;div id="element4"&gt;
                              &lt;label for="label6"&gt;Label6&lt;/label&gt;
                              &lt;input id="label7" name="labelname7" type="text" size="2" maxlength="2" value="" class="text disabled" disabled=""&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                  &lt;/fieldset&gt;
              &lt;/form&gt; 
  
          &lt;/iframe&gt;
      &lt;/form&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p><strong>Code Extract:</strong></p>
  
  <pre><code>WebDriverWait wait_iframe = new WebDriverWait(driver, 20000);
  
  wait_iframe.until(ExpectedConditions.visibilityOfElementLocated((By.id("element2"))));
  
  calling_function(sh1.getCell(col + 10, row).getContents(), 
                  sh1.getCell(col + 11, row).getContents(),
                  sh1.getCell(col + 12, row).getContents(), 
                  sh1.getCell(col + 14, row).getContents());                      
  
  public static void called_funciton(String string1, String string2,
          String string3, String string4) {
          driver.findElement(By.name("Element1 Name")).sendKeys(string1);
          driver.findElement(By.id("Element2 ID")).sendKeys(string2);
          driver.findElement(By.id("Element3 ID")).sendKeys(string3);
          driver.findElement(By.id("Element4 ID")).sendKeys(string4);
          driver.findElement(By.name("submitButton")).click();
      }
  </code></pre>
  
  <p>Do let me know if require any further details!</p>