Questo codice è in groovy, quindi molto probabilmente avrai bisogno di fare qualche rielaborazione. Il primo parametro è un url, il secondo è un contatore per limitare i tentativi.
public boolean selectWindow(window, maxTries) {
def handles
int tries = 0
while (true) {
try {
handles = driver.getWindowHandles().toArray()
for (int a = handles.size() - 1; a >= 0 ; a--) { // Backwards is faster with FF since it requires two windows
try {
Log.logger.info("Attempting to select window: " + window)
driver.switchTo().window(handles[a]);
if (driver.getCurrentUrl().equals(window))
return true;
else {
Thread.sleep(2000)
tries++
}
if (tries > maxTries) {
Log.logger.warn("Cannot select page")
return false
}
} catch (Exception ex) {
Thread.sleep(2000)
tries++
}
}
} catch (Exception ex2) {
Thread.sleep(2000)
tries++
}
}
return false;
}
Come funziona switchto(). Cornice (0) gestire iframe VS. frame-in-frame? Il tag "frameset" è contato? – djangofan
@djangofan Buona domanda. Non lo so, non ho mai usato il parametro numero. Immagino che non contenga l'elemento '
Anche se questo è vecchio, pubblicherò per altri, dalla mia esperienza non ** conta ** elementi 'frameset'. – aurbano