Here is the situation:
- Perform an activity in the main window.
- Click on "Save" button which triggers a confirmation popup with "OK" and "CANCEL" buttons.
- Select "OK" on the confirmation popup and another success popup appears with an "OK" button.
- Click on "OK" on the success popup.
- Switch back to the main window.
The popups mentioned above are HTML based. How can I handle this scenario in Selenium? I am new to Selenium and I am currently stuck at this point.
https://i.sstatic.net/SGfKR.png
Code
String ParentWindow = driver.getWindowHandle(); //switching from parent to pop up window
for (String Child_Window : driver.getWindowHandles()) {
driver.switchTo().window(Child_Window);
WebDriverWait wait = new WebDriverWait(driver, 30);// 1 minute
wait.until(ExpectedConditions.visibilityOfElementLocated(By.name("test")));
driver.findElement(By.xpath("//input[@value='test']")).click();
}
driver.switchTo().window(ParentWindow);
HTML
<div>
<div class="msgBoxContainer">
<div id="msgBox1473308035532Image" class="msgBoxImage">
<img src="styles/images/confirm.png">
</div>
<div id="msgBox1473308035532Content" class="msgBoxContent">
<p>
<span>Are you sure you want to Save??</span>
</p>
</div>
</div>
<div id="msgBox1473308035532Buttons" class="msgBoxButtons">
<input id="msgBox1473308035532FirstButton" class="msgButton" type="button" value="Yes" name="Yes">
<input class="msgButton" type="button" value="No" name="No">
</div>
</div>
</div>
// Upon clicking OK on the first popup, the corresponding div is destroyed and a new div for the second popup is generated.
<div id="msgBox1473308225709" class="msgBox" style="background-image: url("styles/images/msgBoxBackGround.png"); opacity: 1; top: 52.5px; left: 566.5px;">
<div class="msgBoxTitle">Information</div>
<div>
<div class="msgBoxContainer">
<div id="msgBox1473308225709Image" class="msgBoxImage">
<img src="styles/images/info.png">
</div>
<div id="msgBox1473308225709Content" class="msgBoxContent">
<p>
<span>Registration completed</span>
</p>
</div>
</div>
<div id="msgBox1473308225709Buttons" class="msgBoxButtons">
<input id="msgBox1473308225709FirstButton" class="msgButton" type="button" value="Yes" name="Yes">
</div>
</div>
</div>