试图找到包装电子邮件Id字段的iframe

时间:2016-08-11 17:12:57

标签: java iframe selenium-webdriver

我想在电子邮件ID框中输入电子邮件ID之前将我的webdriver切换到iframe。我无法找到电子邮件ID框周围的iframe。

如何找到iframe以使下面的代码有效?

以下是java webdriver代码,

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class HandlingIframes {

    public static void main(String[] args) throws InterruptedException {

        WebDriver driver = new FirefoxDriver();

        driver.navigate().to("http://www.firstcry.com/");

        Thread.sleep(3000);     

        driver.switchTo().frame(driver.findElement(By.xpath(".//*[@id='amt']/div[2]"))); //This locator is not working.

        driver.findElement(By.xpath(".//*[@id='Email']")).sendKeys("happita@gmail.com");

        Thread.sleep(4000);

    }

}

1 个答案:

答案 0 :(得分:0)

我转到了页面源代码,找到了iframe的id并使用了它。下面的代码工作正常。

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class HandlingIframes {

    public static void main(String[] args) throws InterruptedException {

        WebDriver driver = new FirefoxDriver();

        driver.navigate().to("http://www.firstcry.com/");

        Thread.sleep(3000);     

        driver.switchTo().frame("iframe_Login");

        driver.findElement(By.xpath(".//*[@id='Email']")).sendKeys("happita@gmail.com");

        Thread.sleep(4000);

    }

}