Jump to content

Javascript/winexist issue


imacleod
 Share

Recommended Posts

An IE page I'm interacting with has some JavaScript validation that pops if it doesn't like what it sees, e.g.:

if (coname.value=='') {
          alert("Select a company for this action");
          return false;
          }

That freezes the script, so I've been trying to test for the existence of the alert window in my code by using WinExist, using the title text (default and explicit modes), and had no joy, it wasn't being detected, even though the title was valid according to the info tool. I  read some other posts on here and tried using its class, and that has the opposite effect, it's true even when the dialogue is not there!

Can anyone point out what I'm doing wrong here?

if WinExists("[CLASS:#32770]") Then
    Send("{ENTER}")
    ConsoleWrite('@@ Debug:' & @ScriptLineNumber & @CRLF )
    ;"Message from webpage", field validation error
    ;log the ID as having issues
        FileWriteLine($sLogFileName, _NowTime() & " " field validation error screen.")
        ;Open a new 'LIST page"
        _IENavigate($oIE, "http://*****")
        ExitLoop
 EndIf

I'm puzzled by the binary WinExists behaviour for the alert dialog: false when I use its title, even if the alert has popped; true when using CLASS, regardless of whether the alert is present.

I'll continue trawling through the other posts, but if anyone can point me in the right direction...

Edited by imacleod
Link to comment
Share on other sites

  • 2 weeks later...

This test script works for me

#include <IE.au3>
#include <MsgBoxConstants.au3>

Adlibregister("test", 300)

; launches a sample page with an alert inside :
;<script>
;   alert("Select a company for this action");
;</script>

Local $oIE = _IECreate("file:///" & @desktopdir & "\test.htm") 

Func test()
   Local $w = WinList("[CLASS:#32770]")
   For $i = 1 to $w[0][0]
      $t = WinGetText($w[$i][1])
      If StringInStr($t, "company") Then Msgbox($MB_TOPMOST,"", "found it")
  Next
EndFunc

 

Link to comment
Share on other sites

That didn't work for me, the ie_create errors. 

Not that I want to seem ungrateful, but can I circle back to the question of why WinExists always returns false when I use the window title, even if/when the alert has popped (I've confirmed the window title using the Info tool) and always returns true when I use the CLASS option (again, confirmed using the window title using the Info tool), regardless of whether the alert is present.

Is that normal? It's beyond my understanding if it is.
Feel free to tell me if I'm asking a stupid question...

Link to comment
Share on other sites

Mikell's code works for me with IE11.

Also this one works :

Func test()
   If WinExists("[CLASS:#32770]", "company") Then
       ControlClick( "[CLASS:#32770]", "Select a company for this action", "OK")
    EndIf
EndFunc

 

Link to comment
Share on other sites

Cheers guys. 

Mikell,
So that illustrates that the class is not unique to the error message I'm trying to trap.

Unfortunately I've missed my window of opportunity to test this easily; I'm going to have to request some dummy IDs that I can test with.

I guess WinExists failing to trap by title must be a timing issue. I have a WinWaitNotActive immediately proceeding the WinExists, the error message is popped by javascript on the next page, a page that loads over a link that has ~120ms RTT, is that likely to need a sleep to allow the error to pop? 

If so, is there a better way of trapping the occasional error state, other than sleeping? I have ~3000 records to process and the WAN delay already means a run through takes a long time...

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...