【发布时间】:2017-01-23 12:00:59
【问题描述】:
我无法在窗口的 iframe 之间切换。我想在网页顶部窗口中选择一个 iframe。
页面的链接是: http://way2automation.com/way2auto_jquery/dropdown.php#example-1-tab-1
我可以找到两个 iframe,但无法切换到 iframe。每个 iframe 都有自己的下拉列表,我需要从中选择元素。
我尝试过使用 driver.switchto(),但它无法识别 iframe。
我的代码是:
public void SimpleDropDown() throws InterruptedException {
dr.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
// dr.findElement(By.xpath("//a[text()='Select Country']")).click();
// dr.switchTo().frame(dr.findElement(By.xpath("//div[@id='example-1-tab-1']//iframe")));
Select dropdown = new Select(dr.findElement(By.xpath("html/body/select")));
dropdown.selectByVisibleText("India");
System.out.println(dropdown.getFirstSelectedOption().getText());
}
public void comboBox() {
dr.switchTo().frame(2);
dr.findElement(By.xpath("//a[text()='Enter Country']")).click();
Select dropdown = new Select(dr.findElement(By.xpath("//select[@id='combobox']")));
dropdown.selectByVisibleText("Portugal");
【问题讨论】:
-
将
Frame index with 0用于first frame -
目标页面需要注册,因此您最好提供适当的
HTML代码。您还需要driver.switchTo().defaultContent();才能切换到下一个iframe