我無法在窗口的iframe之間切換。我想在網頁的頂部窗口中選擇一個iframe。切換到Selenium-Java中的iframes
頁面的鏈接是: http://way2automation.com/way2auto_jquery/dropdown.php#example-1-tab-1
我可以找到兩個I幀,但不能切換到I幀。每個iframe都有自己的下拉列表,我需要從中選擇元素。
我試過使用driver.switchto(),但它不識別iframes。
我的代碼是:
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");
使用'幀索引對於'第一幀' – NarendraR
目標頁面需要註冊,所以你最好提供適當的'HTML'代碼。在切換到下一個iframe之前,您還需要'driver.switchTo()。defaultContent();' – Andersson