我想在电子邮件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);
}
}
答案 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);
}
}