18 January 2026:


This forum is now archived and is in read-only mode. Please continue discussions on our improved new Sahi Pro Community forum.



Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.

Regular expressions and _popup

JesperJesper Members
edited February 2013 in Sahi Pro
Hi,

I am currently using the trial version of Sahi Pro (4.5.1), and I am liking it so far, except for this one thing I've been struggling with for hours now: popups. I am trying to log in on a site that is open in a popup and assert that I was successful, and depending on the state I can get redirected to different pages with different titles. I am able to find it while it has its first title, but not with any regular expressions. After it changes title once, I am unable to get a hold of it, not by using the exact title nor by regular expressions. I have also been unable to save the reference with _set, is this not possible?

var $popup;
_set($popup, _popup("Title"));
$popup._setValue(_textbox("example"), $example); //Cannot call method "_setValue" of undefined

However, this works:

_popup("Title")._setValue(_textbox("example"), $example);

The popup can redirect to two different pages, the first one actually doesn't contain any html, it's just some text, so it gets the HTTP "303 Object Moved" title. The other page has a title with a Swedish character (ö), which shows as a ? in the logs (when I tried finding it using the exact title). Thinking that this may be a problem I tried using a regular expression to replace this one character with a dot, but it did not work. I tried many different regular expressions, finally I tried just:

_popup(/.*/)

But even this fails. In some cases the test just times out and I get the error "did not complete in <150 seconds", but when I don't get that I get "Window with name [/.*/] not found". Am I missing something? Is there another way to handle popups besides _popup? Is there no way to retrieve them by index or something?

Best Answer

  • Answer ✓
    Hi Jesper,

    Use _selectWindow instead of prepending _popup before every statement.

    Eg.
    _selectWindow("Title"); // switch to popup window with title
    _setValue(_textbox("example"), $example); // no need to prefix _popup
    _selectWindow(); // back to base window
    

    Use
    _selectWindow("/.*/");
    if you want to point to a popup window without referring to its title.

    Regards,
    Narayan



Answers

  • Hi,
    Sahi recognizes popup onlly if _popup(). is the first part of a statement. It removes _popup(). and goes to that particular popup to execute whatever is after that.

    _set($popup, _popup("Title")); is not starting with _popup. So it will not work. You can try now with this in mind and see if this works.

    Thanks,
  • Thank you narayan, exactly what I was looking for.
Sign In or Register to comment.