我在网页上有按钮。单击该按钮后,将弹出一个弹出窗口以选择一些信息。一旦我从弹出窗口中选择了信息,它就会自动关闭。 我试着按照以下方式处理它:
public void selectCustomerFromPopUp(String Customer)
{
//By clickSelectCustomerIcon=By.xpath("//* [@id='dDiv']/table[6]/tbody/tr[2]/td[4]/a/img");
Set<String> ids=driver.getWindowHandles();
Iterator<String> getId=ids.iterator();
String quoteInfoWindow=getId.next();
String selectCustomerPopUp=getId.next();
driver.switchTo().window(selectCustomerPopUp);
WebElement customerSelectTable=driver.findElement(By.xpath("//*[@id='bsData']/table[2]"));
List<WebElement>rows=customerSelectTable.findElements(By.tagName("tr"));
for(WebElement eachrow:rows)
{
List<WebElement> column=eachrow.findElements(By.tagName("td"));
for(WebElement text:column)
{
if(text.getText().contains(Customer))
{
text.click();
break;
}
}
}
}
但是在控制台中我看到目标窗口已经关闭。
Exception in thread "main" org.openqa.selenium.NoSuchWindowException: no such window: target window already closed
from unknown error: web view not found
(Session info: chrome=56.0.2924.87)