Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

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();
    }   

}

}
share|improve this question
1  
Can you post your code where you try to switch to the iframe? What happens when you try it - does it throw an error? –  vincebowdren May 9 '13 at 14:14
    
@vincebowdren I have added the entire Java code now. I am not able to locate the PSEDITBOX. The code works fine till wd1.switchTo().defaultContent() –  Saik0 May 9 '13 at 14:23
2  
Thanks, that's useful. From a look at the code, it's not obvious whether you have a problem with switching, or with that particular field PSEDITBOX. If you move the call to PSEDITBOX further up (before you switched to the iframe), does it work there? –  vincebowdren May 9 '13 at 14:42
    
@vincebowdren Not does not work. I commented the 2nd swtichTo –  Saik0 May 9 '13 at 14:47
2  
That sounds like you have a problem with your PSEDITBOX control then. Is it in the iframe, or in the default content? And can you verify that it definitely exists, uniquely, as identified by the class? –  vincebowdren May 9 '13 at 15:13
show 1 more comment

1 Answer

up vote 0 down vote accepted

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");
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.