-2

I need to confirm a modal popup. I have a form which I fill up and have to move to next page. When I click continue, a modal popup appears asking if the details filled are correct?

There are two button and some other description on it. One button reads cancel and other says Yes, information is correct. I tried switching to the modal element by

driver.switchTo().frame(0);  // there is only one popup

However, whatever I do with webDriver after that results in NullPointerException as no webelement is found.

This is what am trying

WebElement modalButtonContainer = AutoUtils.findElementByClassName(modalOverlay, "modalButtonContainer");
WebElement modalButton = AutoUtils.findElementByClassName(modalButtonContainer, "buttonClass");
modalButton.click();

But it all results in NullPointer. How do I click the modalButton?

roger_that
  • 9,493
  • 18
  • 66
  • 102

3 Answers3

1

If I recall correctly driver.switchTo().frame(0); switches to <iframe> elements. Here you're talking about the popup. This one again depends, if this is a typical JavaScript popup invoked with javascript:alert('popup') or similar, then

Alert alert = driver.switchTo().alert();
alert.accept();

is the way to go. Otherwise, if it's some bootstrap popup, then you don't need any switching at all, maybe some FluentWait only.

(if it doesn't work, please share the DOM)

Pijotrek
  • 2,821
  • 1
  • 18
  • 32
0

As there are two buttons on the pop up, and if both buttons class name is same ('buttonClass')

Better to try identify the button with some other locator either with name or some other unique attribute.

WebElement modalButtonContainer = AutoUtils.findElementByClassName(modalOverlay, "modalButtonContainer");
WebElement modalButton = AutoUtils.findElementByName(modalButtonContainer, "Cancel");
                       (or)
WebElement modalButton = AutoUtils.findElementByName(modalButtonContainer, "Yes, information is correct.");
modalButton.click();
SeJaPy
  • 284
  • 1
  • 6
  • 18
0

NullPointerException doesn't mean element not found. It means that you're trying to access an object, which is not yet initialized. Check your stacktrace. It'll show you an exact line, where you've tried to access an uninitialized object. It might be either page object or web element you're interacting with. When you detect an issue, verify that new operator is used. Or if you're using PageFactory, don't forget about calling initElements.

Serhii Korol
  • 843
  • 7
  • 15