driver.switchTo()帧(driver.findElement(By.xpath( “/ HTML /体/形式/ DIV [12] / DIV [1] / DIV [5] / iframe中”)));
new Select(driver.findElement(By.id("ddlFileExtensions"))).selectByVisibleText("DLA-Extension");
driver.findElement(By.cssSelector("option[value=\"DLA-Extension\"]")).click();
driver.findElement(By.xpath("/html/body/form/div[3]/fieldset/table/tbody/tr[3]/td[2]/div[1]/input[1]")).sendKeys("TestDLA");
driver.findElement(By.xpath("/html/body/form/div[3]/fieldset/table/tbody/tr[4]/td[3]/a/input[1]")).click();
//Switch to new window opened
for(String winHandle : driver.getWindowHandles()){
driver.switchTo().window(winHandle);
}
driver.findElement(By.xpath("/html/body/form/div[3]/div[3]/div/table[1]/tbody/tr[1]/td[3]/a")).click();
driver.findElement(By.xpath("/html/body/form/div[3]/div[3]/div/table[10]/tbody/tr[2]/td[3]/a")).click();
driver.findElement(By.xpath("/html/body/form/div[3]/div[4]/a[1]/input[1]")).click();
driver.switchTo().frame(driver.findElement(By.xpath("/html/body/form/div[12]/div[1]/div[5]/iframe")));
//driver.findElement(By.xpath("/html/body/form/div[3]/div/a[1]/input[1]")).click();
mouseClickByLocation("/html/body/form/div[3]/div/a[1]/input[1]");
答案 0 :(得分:2)
我的答案不符合你的代码。但我告诉你如何实现这一目标。只需确保在代码中正确放置了所有步骤即可。
第1步:存储主窗口句柄
String Parentwindow = driver.getWindowHandle( );
步骤2:点击将打开新浏览器窗口的链接
步骤3:切换到新的打开浏览器窗口。
for ( String currentwindow : driver.getWindowHandles())
driver.switchTo( ).window(currentwindow);
{
// Perform your operations on the current window
driver.close( )
}
第4步:返回主窗口
driver.switchTo().window(Parentwindow);