title: testing submit button with selenium webDriver
body: <p>My html form contains multipl html tags such <code>&lt;form&gt;</code> </p>
  
  <p>My html file: myFile.html</p>
  
  <pre><code>&lt;body&gt;
          &lt;div class="globalContainer"&gt;                              
              &lt;div class="test1" id="formM" width="848" height="720" method="post" name="devis" onreset="return vider();"&gt;
                  &lt;div class="content-1" id="cadreGlob"&gt;  
                      &lt;div id="contentForm"&gt;
                          &lt;div class="preview"&gt;
                              &lt;div class="left_col"&gt;
                                  &lt;fieldset id="haut"&gt;                    
                                      &lt;label  class="labelForm" id="labelPriorite"&gt;label1:&lt;/label&gt;
                                          &lt;select id="selectPrio"&gt;
                                              &lt;option value="labT"&gt;subLabel11&lt;/option&gt;
                                              &lt;option value="labP"&gt;subLabel12&lt;/option&gt;
                                          &lt;/select&gt;&lt;p&gt;&lt;/p&gt;                                                                                                           
                                      &lt;form enctype="multipart/form-data" method="post"&gt;
                                          &lt;label class="labelForm" id="labelFile1"&gt;label2:&lt;/label&gt;
                                          &lt;input  id="upload1" type="file" name="file[]" /&gt;
                                      &lt;/form&gt;                             
                                  &lt;/fieldset&gt;                     
                              &lt;/div&gt;                  
                              &lt;div class="right_col"&gt;                                             
                                  &lt;fieldset id="haut"&gt;
                                      &lt;form name="page"&gt;
                                          &lt;label class="labelForm" for="cb" id="labelPopulation"&gt;lebel3:&lt;/label&gt; 
                                              &lt;input type="checkbox" id="cb" name="cb" checked="checked" onclick="valid();showPop();" /&gt;&lt;br /&gt;            
                                          &lt;label class="labelForm" for="ta" id="labelMessage2"&gt;label4:&lt;/label&gt; 
                                              &lt;textarea disabled="true" id="ta" name="ta" cols="22" rows="9"&gt;&lt;/textarea&gt;
                                          &lt;label class="labelForm" id="labelFile2" &gt;label5:&lt;/label&gt;
                                          &lt;input id="upload2" type="file" name="valider" id="butonParc" disabled="disabled"/&gt;                              
                                      &lt;/form&gt;                                               
                                  &lt;/fieldset&gt;
                              &lt;/div&gt;              
                              &lt;div class="left_col"&gt;
                              &lt;p&gt;&lt;/p&gt;
                                  &lt;fieldset id="bas"&gt;                 
                                      &lt;label class="labelForm" id="labelServiceOp"&gt;label6:&lt;/label&gt;
                                          &lt;select id="selectServOp"&gt;
                                              &lt;option value="def"&gt;subLabel61&lt;/option&gt;
                                              &lt;option value="sec"&gt;subLabel62&lt;/option&gt;
                                          &lt;/select&gt;&lt;p&gt;&lt;/p&gt;                                                
                                  &lt;/fieldset&gt;
                              &lt;/div&gt;              
                              &lt;div class="right_col"&gt;
                                  &lt;p&gt;&lt;/p&gt;
                                  &lt;fieldset id="bas"&gt;
                                      &lt;label class="labelForm" id="labelAdressage" &gt;label7:&lt;/label&gt;
                                          &lt;select name="ToutePopD" id="ToutePopD"&gt;
                                              &lt;option value="toujours"&gt;subLabel71&lt;/option&gt;
                                              &lt;option value="parfois"&gt;subLabl72&lt;/option&gt;
                                          &lt;/select&gt;
                                          &lt;select name="ToutePopA" id="ToutePopA"&gt;
                                              &lt;option value="toujours"&gt;subLabl73&lt;/option&gt;
                                              &lt;option value="parfois"&gt;subLabel74&lt;/option&gt;
                                          &lt;/select&gt;
                                  &lt;/fieldset&gt;
                              &lt;/div&gt;                                            
                              &lt;div class="right_col"&gt;&lt;p&gt;&lt;/p&gt;
                                  &lt;form action="submit.html" id="sub" name="formValid"&gt;
                                      &lt;input type="submit" id="validation" value="validate" name="submit" /&gt;
                                  &lt;/form&gt; &lt;p&gt;&lt;/p&gt;                                                                                       
                                      &lt;script&gt;
                                      function vider()
                                      {
                                          document.getElementById("formM").value = "";
                                          return false;
                                      };
                                      &lt;/script&gt;                                                                                   
                                  &lt;input type="reset" id="cancel" value="Cancel"name="reset" /&gt;
                              &lt;/div&gt;                  
                          &lt;/div&gt;
                      &lt;/div&gt;      
                  &lt;/div&gt;      
              &lt;/div&gt;  
          &lt;/div&gt;      
      &lt;/body&gt;
  </code></pre>
  
  <p>My first problem
  when i execute this command</p>
  
  <pre><code>...
  ...
  this.driver.findElement(By.id("validation")).click();
  ...
  ...
  </code></pre>
  
  <p>My test is not switch to the url : submit.html</p>
  
  <p>My submit.html</p>
  
  <pre><code>    &lt;body&gt;
          &lt;h2&gt;&lt;center&gt;Form validation with Succee&lt;/center&gt;&lt;/h2&gt;
      &lt;/body&gt;
  </code></pre>
  
  <p>My second problem:</p>
  
  <p>When i execute the following code, i have an error : <code>Unable to locate element : {"method":"id","selector":"sub"}</code></p>
  
  <pre><code>public class SeleniumTest {
      private WebDriver driver;
      private String baseUrl;
      private boolean acceptNextAlert = true;
      private final StringBuffer verificationErrors = new StringBuffer();
  
      @Before
      public void setUp() throws Exception {
          final Properties properties = System.getProperties();
          this.baseUrl = properties.getProperty("base.url", "myIp:8080/project");
      }
  
      @Test
      public void firefoxTest() throws Exception {
          this.driver = new FirefoxDriver();
          testSelenium();
          verifyValidation(this.baseUrl +"submit.html");
      }
  
      private void testSelenium() throws Exception {
          this.driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
          this.driver.get(this.baseUrl + "myFile.html");
          new Select(this.driver.findElement(By.id("formM")).findElement(By.xpath("//fieldset[@id='haut']/select[1]"))).selectByVisibleText("subLabel11");
          this.driver.findElement(By.id("upload1")).sendKeys("myUrl\\myFile.txt");       
          this.driver.findElement(By.id("validation")).click();
      }
      private void verifyValidation(String urlValidation) {
          String submit =
                  this.driver.findElement(By.id("sub")).getAttribute("action");
          if (submit == urlValidation) {assertEquals("url problem : ", submit, urlValidation);
      }
  
  
      @After
      public void tearDown() throws Exception {
          this.driver.quit();
          final String verificationErrorString = this.verificationErrors.toString();
          if (!"".equals(verificationErrorString)) {
              fail(verificationErrorString);
          }
      }
  
      private boolean isElementPresent(final By by) {
          try {
              this.driver.findElement(by);
              return true;
          } catch (final NoSuchElementException e) {
              return false;
          }
      }
  
      private String closeAlertAndGetItsText() {
          try {
              final Alert alert = this.driver.switchTo().alert();
              final String alertText = alert.getText();
              if (this.acceptNextAlert) {
                  alert.accept();
              } else {
                  alert.dismiss();
              }
              return alertText;
          } finally {
              this.acceptNextAlert = true;
          }
      }
  }
  </code></pre>
  
  <p>I don't know why WebDriver can not find my id ! ?</p>
  
  <p>Thanks for help !</p>