Selenium WebDriver: Unable to switch to apparent pop-up



  • I am trying to automate Peoplesoft 9 based Web application on Firefox 20.0.1. On clicking a search icon another form opens which I thought to be a pop-up and tried my code - driver.switchTo.alert("popup_name") but this threw an exception Alert not present!. Then I tried to revisit the HTML and found it to be within an iframe and, tried to switch to the iframe but in vain! Below is the CSS path of the item I want to select - html body.PSSRCHPAGE form div#win0divSEARCHADV table.PSPAGECONTAINER tbody tr td select##ICKeySelect.PSDROPDOWNLIST The HTML tag hierarchy looks like - iframe > .. form > .. select > .. Java Code - import java.util.concurrent.TimeUnit; // import javax.swing.JOptionPane; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.support.ui.Select; public class SeleniumTest3 { /** * @param args / public static void main(String[] args) { // TODO Auto-generated method stub try { // open a firefox driver WebDriver wd1 = new FirefoxDriver(); wd1.manage().window().maximize(); wd1.manage().timeouts().implicitlyWait(59, TimeUnit.SECONDS); // open the url and login wd1.navigate().to("http://www.sample.com"); wd1.findElement(By.name("userid")).sendKeys("abc"); wd1.findElement(By.name("pwd")).sendKeys("abc2013"); wd1.findElement(By.xpath("//input[@type='image']")).click(); // click the timesheet link and switch to iframe wd1.findElement(By.linkText("Timesheet")).click(); wd1.switchTo().frame("TargetContent"); // click the search task icon wd1.findElement(By.id("USER_FIELD_3$prompt$0")).click(); wd1.switchTo().defaultContent(); // select option from combo-box wd1.findElement(By.className("PSEDITBOX")).sendKeys("Design"); new Select(wd1.findElement(By.id("#ICKeySelect"))).selectByVisibleText("Task Name"); } catch (Exception exc) { // JOptionPane.showMessageDialog(null,"Better Luck Next Time :(" /+ exc.getMessage()*/); exc.printStackTrace(); } } }



  • Solved now. The PSEDITBOX is contained in another iframe which I missed. So I have just added one line now and it solved the issue - wd1.switchTo().frame("popupFrame"); wd1.findElement(By.className("PSEDITBOX")).sendKeys("Design");



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2