我打开一个弹出窗口,通向谷歌:
if (popup == 'closed') {
// do stuff
}
如何检测用户何时关闭此窗口?
例如:
List<String> specificationItems = new ArrayList<String>();
List<String> specificationValues = new ArrayList<String>();
List<WebElement> all_specificationItems = driver.findElements(By.xpath("//div[@class='specificationList']/ul[@class='inner']//li[@class='specificationItem']/dl/dt[@class='icon']/span[starts-with(@id,'Body_ContentPlaceHolderContent_ContentPlaceHolderContent_VehicleFeatures_FeatureList_FeatureText_')]"));
List<WebElement> all_specificationValues = driver.findElements(By.xpath("//div[@class='specificationList']/ul[@class='inner']//li[@class='specificationItem']/dl//span[@class='valueContent']"));
int size = all_specificationItems.size();
for(WebElement ele:all_specificationItems)
specificationItems.add(ele.getAttribute("innerHTML"));
for(WebElement elem:all_specificationValues)
specificationValues.add(elem.getAttribute("innerHTML"));
for(int i=0;i<size;i++)
System.out.println(specificationItems.get(i) + " has a value of " + specificationValues.get(i));
答案 0 :(得分:1)
一个窗口有一个closed
字段,指示它是否已关闭,所以如果你想在用户关闭弹出窗口时执行某些操作,你可以这样做:
var popup = window.open(...)
var intervalRef = setInterval(function() {
if(popup.closed) {
clearInterval(intervalRef);
// Do whatever you want to do when the user closes the popup here
}
}, 100);