jot
jot

Reputation: 11

not able to switch to frame, getting element not found even when i pass correct frame id or xpath

url = http://www.yopmail.com/en/

public class ReadEmailForEmailChange {

    WebDriver drive =  new FirefoxDriver();     
    drive.get("http://www.yopmail.com/en/");

    // I am able to get the size of frms
     int size = drive.findElements(By.tagName("iframe")).size();

     // this is the user name send keys.
     WebElement emai = (WebElement) drive.findElement(By.xpath("//input[@id='login']"));
     emai.sendKeys("testdenmark");

    // this is button to click. it is working as well
    WebElement emaenter = (WebElement)drive.findElement(By.xpath("//input[@title='Check inbox @yopmail.com']"));
    emaenter.click();

    // this is 1st frame. i am able to switch to this frame with no prob
    drive.switchTo().frame(drive.findElement(By.id("ifinbox")));


    // this is to find the email based on subject text. it is working fine
     WebElement emailopen = (WebElement) drive.findElement(By.xpath("//span[@class='lms' and text()='email verification']"));

     emailopen.click();      
     System.out.println("got to the emial.");

    // here comes problem. i am 100% that Id is correct or xpath is correct

but i am not able to switch to this frame. I am getting element not found except

    //WebElement frame = drive.findElement(By.xpath("//tr//td//iframe[@id='ifmail']"));

    //drive.switchTo().frame(drive.findElement(By.id("ifmail")));
     //drive.switchTo().frame(drive.findElement(By.xpath("//iframe[@id='ifmail']")));

this will happen after i switch to the frame

        drive.findElement(By.xpath("//a[text()='Verify email']")).click();

The iframe is

<iframe class="whc" frameborder="0" scrolling="auto" id="ifmail" name="ifmail" src=""></iframe>

Upvotes: 1

Views: 787

Answers (1)

Taran
Taran

Reputation: 531

Sounds like you need to wait for the iframe to appear first. Try a webdriver wait before attempting to switch to the IFrame.

WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("ifmail")));

Upvotes: 1

Related Questions