title: one frame containing different forms
body: <p>I am working on a website where I have to perform some operations inside iframes, so far I am able to switch to the frame and perform operations on the first page. But as soon as it navigates to the second page it doesn't work. I tried to check if there are more than one iframes, but there is only one.</p>
  
  <p>On the first page, it shows the following as seen int the image:</p>
  
  <p><a href="https://i.stack.imgur.com/PXLgk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PXLgk.png" alt="enter image description here"></a></p>
  
  <p>On the second navigated page:</p>
  
  <p><a href="https://i.stack.imgur.com/3SU2C.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3SU2C.png" alt="enter image description here"></a></p>
  
  <p>Here is a screenshot of the HTML code of iframe:</p>
  
  <p><a href="https://i.stack.imgur.com/IobLb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/IobLb.png" alt="enter image description here"></a></p>
  
  <p>In both the cases, the iframe is common but the description given is different, I am not able to identify the problem as per why it is not selecting the element.</p>
  
  <p>can anybody give suggestion as per why this has occurred and what should I do to make it work fine?</p>
  
  <p>This is the code which i have written for  first two pages</p>
  
  <pre><code>// page1//select the particular size
  driver.manage().timeouts().implicitlyWait(1000, TimeUnit.SECONDS);
  JavascriptExecutor jse = (JavascriptExecutor) driver;
  jse.executeScript("window.scrollBy(0,100)", "");
  WebElement wi = driver.findElement(By.xpath("//div[contains(text(),'" + size + "')]/input[@type='radio']"));
  if (wi.isDisplayed())
  {
      System.out.println("displayed");
      driver.findElement(By.xpath("//div[contains(text(),'" + size + "')]/input[@type='radio']")).click();
  }
  else
  {
      System.out.println(" not displayed");
  }
  // get started
  driver.findElement(By.xpath("//input[contains(@src,'get-started')]")).click();
  driver.manage().timeouts().implicitlyWait(1000, TimeUnit.SECONDS);
  // Actions act = new Actions(driver);
  // select a theme
  driver.manage().timeouts().implicitlyWait(1000, TimeUnit.SECONDS);
  System.out.println(" currently switching");
  WebElement iframe = driver.findElement(By.xpath("//td/iframe[@id='mainFrame']"));
  driver.switchTo().frame(iframe);
  System.out.println("switching done");
  String url1 = "http://www.photojaanic.sg";
  if (url.equals(url1))
  {
      int sg = 20;
  
      jse.executeScript("window.scrollBy(0,200)", "");
      driver.findElement(
              By.xpath("//div[@class='div_img']/img[@src='http://services.nvi.co.in/themes/" + sg + "/3/" + themename + "/CF.jpg']"))
              .click();
  }
  else
  {
      int in = 19;
  
      action.moveToElement(driver.findElement(
              By.xpath("//div[@class='div_img']/img[@src='http://services.nvi.co.in/themes/" + in + "/3/" + themename + "/CF.jpg']")))
              .click();
  }
  driver.manage().timeouts().implicitlyWait(1000, TimeUnit.SECONDS);
  driver.findElement(By.xpath("//button[contains(text(),'Select this theme')]")).click();
  
  driver.manage().timeouts().implicitlyWait(1000, TimeUnit.SECONDS);
  
  // page2
  jse.executeScript("window.scrollBy(0,200)", "");
  driver.switchTo().defaultContent();
  WebDriverWait wait = new WebDriverWait(driver, 20);
  wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.tagName("html")));
  driver.manage().timeouts().implicitlyWait(1000, TimeUnit.SECONDS);
  driver.findElement(By.xpath("//div[@id='step_wrapper']/form//div[contains(text(),'" + papertype + "')]")).click();
  // String selectpapertype1 ="//button[contains(text(),'Select:"+papertype+"')]";
  
  driver.manage().timeouts().implicitlyWait(1000, TimeUnit.SECONDS);
  
  action.moveToElement(driver.findElement(By.xpath("//div[@id='step_wrapper']/form//button[contains(text(),'Select:" + papertype + "')]"))).perform();
  </code></pre>