Swa Swa - 1 year ago 63
HTML Question

How to handle HTML popup which appears as per database condition in selenium webdriver

My Scenario is

  1. Enter username, password and click on

  2. system checking the condition in database as
    this user already login = true

  3. The pop up appears as
    forcefully login

  4. Click on Pop up OK button.

  5. Appearing Location drop down and GO button and system moving ahead.

  6. If
    this user already login = false

  7. The pop up doesn't appear.

  8. System executing step 5.

The question is 'how do i handle above Condition' ?
Because that pop up is not appearing each time

HTML code of pop up is:

<div id="msgBox1473647409235" class="msgBox" style="background-image: url("styles/images/msgBoxBackGround.png"); opacity: 1; top: 37px; left: 566.5px;">
<div class="msgBoxTitle">Confirm</div>
<div class="msgBoxContainer">
<div id="msgBox1473647409235Image" class="msgBoxImage">
<img src="styles/images/confirm.png">
<div id="msgBox1473647409235Content" class="msgBoxContent">
User already login
Forcefully Login?
<div id="msgBox1473647409235Buttons" class="msgBoxButtons">
<input id="msgBox1473647409235FirstButton" class="msgButton" type="button" value="OK" name="OK">
<input class="msgButton" type="button" value="Cancel" name="cancel">

Answer Source

(Assuming you're using Java) You just simply check using findElements() as below :-

//Enter login credentials and click on login button 

//Now check for popup if to be appears with Ok button 
List<WebElement> elements = driver.findElements(By.className("msgBox"));
if(elements.size() > 0 && elements.get(0).isDisplayed() && elements.get(0).isEnabled())
    //Now find Ok or cancel button to process 
    WebElement okButton = element.get(0).findElement(By.name("OK"));

    WebElement cancelButton = element.get(0).findElement(By.name("cancel"));

//Not handle your 5 steps and more Appearing Location drop down and GO button and system moving ahead.
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download