I'm just starting to work with Java and Selenium and stuck with getting a NullPointerException in the following if statement when trying to switch to a third window opened. My test has two windows opened already. Each window has its handle saved into a variable.
Then this method LessonHeader.clickLessonPreview(); opens a third window that I need to switch to.
String windowLMS = ApplicationManager.driver.getWindowHandle();
String windowLD = ApplicationManager.driver.getWindowHandle();
private void previewLesson() {
WebDriverWait wait = new WebDriverWait(ApplicationManager.driver, 5);
assert ApplicationManager.driver.getWindowHandles().size() == 2;
LessonHeader.clickLessonPreview();
wait.until(numberOfWindowsToBe(3));
for (String windowHandle : ApplicationManager.driver.getWindowHandles()) {
if (!windowLMS.contentEquals(windowHandle) && !windowLD.contentEquals(windowHandle)) {
ApplicationManager.driver.switchTo().window(windowHandle);
break;
}
wait.until(elementToBeSelected(By.id("titlestartbutton")));
}
}
The exception happens in this line: if (!windowLMS.contentEquals(windowHandle) && !windowLD.contentEquals(windowHandle)) {
Aucun commentaire:
Enregistrer un commentaire