0

How to handle this kind of pop-up. My goal is to get the message when Submit button clicked then validate it againts my own text (maybe using assert). I've tried to locate the element using firepath (xpath) but when i click locate Element button on firebug, the pop-up disappear.

Here is the screenshot of the pop-up.

popUp

Here is the code :

<p class="errors"></p>
<input id="email" class="form-control" type="email" value="" name="email" required="" oninput="setCustomValidity('')" oninvalid="this.setCustomValidity('Email Cannot Be Empty')" placeholder="Email *" data-placeholder="X" data-format="">

Thank you in advance.

3 Answers3

0

If the element is not inside a iframe, then you can directly try as follows:

String emailId  = driver.findElement(By.id("email")).getText()  
// write string equals login here comparing emailId that is captured and the one you want to compare to.

if not, first find the iframeand switch to it and then use above code to find the element. More detailed answer related to switching b/w frame is here


Finding the elements in the Pop-up:

Instead of clicking on the Locate Element button (of Firebug) first, Right click on the element you want to find in the Pop-up, and select Inspect with Firebug, which gives the corresponding HTML code for the element.

Community
  • 1
  • 1
Naveen Kumar R B
  • 6,248
  • 5
  • 32
  • 65
  • Hi Naveen, my goal is to get the text from that pop-up and validate it againts my own text to make sure the validation of the field worked. As far as i see, there is no iframe on the code. Thank you. – Hendi Ravasia Dec 28 '16 at 02:27
  • updated code. retrieve the text of web element using `getText` method. once stored in a string, it is just a String comparison using Jaa libraries. If you are using any framework, you can pass it as an actual value to the Assertion methods like `assertEqual(actual, expected)` etc. – Naveen Kumar R B Dec 28 '16 at 05:52
  • Thanks for your reply. i get about the web element, asserting and getText things, i've problem to get the warning message when i click the submit button because the it will dissapear if i make any event (even scrolling page). So, when the driver try to catch the message, its already gone. – Hendi Ravasia Dec 28 '16 at 06:24
  • I am confused. why do you make any event in automation, which would result in disappearing of the message? could you please clear what you are trying and what you want to achieve? also, refer `Finding the elements in the Pop-up:` section in my answer. – Naveen Kumar R B Dec 28 '16 at 06:42
  • I want to check whether the "is empty" field validation is working or not. The step is leaving the field blank then click submit button. My expectation, there will be a pop-up message appear. After that i'll get the content message of the pop-up then compare it to my own text. The problem is when i try to get the content, the pop-up dissapear. – Hendi Ravasia Dec 28 '16 at 07:00
  • ok. As I said earlier, instead of clicking on `Select Locator` from Firebug, Right-click on the pop-up and select `Inspect element with Firebug` is not working for you? – Naveen Kumar R B Dec 28 '16 at 07:09
  • check this one. similar issue if the pop-up is javascript alert. http://stackoverflow.com/questions/10633889/read-message-from-alert-and-click-on-ok – Naveen Kumar R B Dec 28 '16 at 08:38
  • Okay, i'll check it, Thank you very much Naveen. – Hendi Ravasia Dec 28 '16 at 12:12
0

From the scrrenshot it looks like a tooltip. Something like when we mouse over Google title in https://www.google.co.in/.

To verify tooltip we can get the attribute 'title' and verify. Example : in https://www.google.co.in/. tooltip is placed in title attribute as below.

title="Google"

<div id="hplogo" style="background-size:272px 92px;height:92px;width:272px" title="Google" onload="window.lol&&lol()" align="left">

For your scenario, the displayed tip message is available in 'oninvalid' attribute as below. So get this attribute value and validate it.

oninvalid="this.setCustomValidity('Email Cannot Be Empty')"

Giri
  • 411
  • 2
  • 18
  • Hi Giri, Its not a tooltips, its like warning message when submit button clicked then the app will validate each field, its empty or not. When field is empty, this message appear on the top of the field. – Hendi Ravasia Dec 28 '16 at 02:20
0

This is a bit late in the game but the way you get the custom validity message and not the generic one you have to call the reportValidity() event within JavaScript in Selenium. You'll see a driver.executeScript() method and this is where you must call the reportValidity event on the element being validated. This is how I did it:

    wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions
        .ElementToBeClickable(By.CssSelector("input#NewPassword.form-control")));
    IWebElement input = driver.FindElement(By.CssSelector("input#NewPassword.form-control"));
    input.SendKeys(string.Empty);
    IWebElement form = driver.FindElement(By.TagName("form"));        
    form.Submit();
    driver.ExecuteScript("document.getElementById('NewPassword').reportValidity();");
    Assert.AreEqual("New password required", input.GetAttribute("validationMessage")); 
Charles Owen
  • 2,403
  • 1
  • 14
  • 25