Jump to content
MakzNovice

How to get Control back of parent browser

Recommended Posts

MakzNovice

Hello Experts,

I am working on modifying table data of a browser currently in IE (soon in FF)

My sequence of operations:

1. Activate Browser

2. Get Browser table

3. Modify data  in table

4. Suppress any warning/error message from webpage

5. Activate the Webpage again 

6. Send {F11} key sequence twice to achieve some update without Updating form ( {F5})

 

My problem is at Step 5, as it activates the wrong window ( last used application rather than my browser window)

My code snippet for it as follows

$bFoundWindow = False
Local $aList = WinList("[REGEXPTITLE:(?i)(.*Internet Explorer.*)]")
Local $hWND = 0 
For $i = 1 To $aList[0][0]
    If False = $bFoundWindow And $aList[$i][0] <> "" And BitAND(WinGetState($aList[$i][1]), 1) Then
        WinActivate($aList[$i][1]) ; 1. Activate Browser window
        WinSetState ( $aList[$i][1], "", @SW_MAXIMIZE)
        $hWND = $aList[$i][1]
        $objEditIE = _IEAttach ($aList[$i][1], "hwnd")
        $oTitles = _IETagNameGetCollection($objEditIE, "TITLE")
        For $oTitle In $oTitles
            $sTitle = $oTitle.innerText
            If $sTitle = $searchString Then
                MsgBox(0,"APPLICATION Found", "Got Edit List Window", 1)
                $bFoundWindow = True
                ExitLoop
            EndIf
        Next
    EndIf
Next
If False = $bFoundWindow Then
    MsgBox(0,"Error","Please launch Edit window for updating values in Browser prior to script execution",10)
    Exit
EndIf

; MY CODE HERE TO MODIFY TABLE 
; 2. Get Browser table
; 3. Modify data  in table

; Check if message from webpage pop-up window exists if so click ok on it
Local $nCounter = 0
Local $nMaxCounter = 5
while 1
    If WinExists("Message from webpage","") Then
        ControlClick("Message from webpage","","Button1","primary",1) ;4. Suppress any warning/error message from webpage
    Else
        $nCounter = $nCounter + 1
        Sleep(100)
        ;MsgBox(0,"Counter", $nCounter, 1)
        If $nCounter = $nMaxCounter Then ExitLoop
    EndIf
WEnd

;5. Activate the Webpage again 
WinActivate($hWND) ; have already tried WinActivate($aList[$i][1]) but no success
;6. Send {F11} key sequence twice to achieve some update without Updating form ( {F5})
Send("{F11}") 
WinActivate($hWND) ;WinActivate($aList[$i][1])
Sleep(100)
Send("{F11}")

Any support will be highly appreciated


It doesn't get easier, you just get better...

Share this post


Link to post
Share on other sites
Danp2

I remember your prior thread. Still unclear why you are using WinList / WinActive with a browser window. I suspect that this could be done with _IEAttach if we had more details about the tab in question.

As far as your posted code, you could save the value of $aList[$i][1] at the point where you set $bFoundWindow = True. Then this value could be used later in the script.

Share this post


Link to post
Share on other sites
MakzNovice

@junkew- Thank you for sharing details for other options, for now I am using IE.au3 and FF.au3 ( since my system has Firefox version 45.0 which works fine with mozrepl) .I am also learning IUIAutomation, which I just started.

@Danp2- Yes it is a variation of my previous topic. I wish I could share link, but its highly customized for organization I work and uses IE and FF as browsers.

Q) Still unclear why you are using WinList / WinActive with a browser window

A) I have multiple windows ( not tabs)  of IE to manage, hence I thought WinList is the only way to first collect required IE window.  ( Please share any snippet that you think can work better for me)

I use WinActivate since I want to bring IE on top so that I can visually see the values being changed; Also in my code logic step 3 

; 3. Modify data  in table

I have used 

_IEAction($td,"click")
_IEAction($td,"focus")

and also want to send F11 key sequences to browser (Is it possible to send F11 without having it on top?)

Q) you could save the value of $aList[$i][1] at the point where you set $bFoundWindow = True.

A) I am doing so inside first loop , instead of inner loop ( how stupid of me).

$hWND = $aList[$i][1]

Will verify the change as soon as I get back to my PC and will post update

Let me know if you can improvements in my script.


 

It doesn't get easier, you just get better...

Share this post


Link to post
Share on other sites
Danp2
1 hour ago, MakzNovice said:

Please share any snippet that you think can work better for me

Look at example 5 in the help file entry for _IEAttach. This is how I would probably do it. If you know the window's title, you could also use it along with the instance number.

1 hour ago, MakzNovice said:

also want to send F11 key sequences to browser (Is it possible to send F11 without having it on top?)

Take a look at the help for ControlSend. Also, check the forums as I believe there are numerous examples of this.

Share this post


Link to post
Share on other sites
MakzNovice

@Danp2- Again thank you ControlSend works smooth. I am going to explore option with _IEAttach but for now, I get what I want t get my job done.

Thank you very much.

 


It doesn't get easier, you just get better...

Share this post


Link to post
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

  • Similar Content

    • yoschga
      By yoschga
      is there a possibility to let ie.au3 click into a form? i use on a project where i need to click into a form where items are loaded just writing it in or fill the form is no option
       

    • RamaKrishna9
      By RamaKrishna9
      What are the minimum system requirements(like Windows OS version, IE browser version, etc,.) for IE.au3(3.3.14.2) to work properly?
    • MakzNovice
      By MakzNovice
      Hello Experts,
      I am working on custom application details of which I am unable to share.
      But here is statement of my problem, I have two IE windows one window with Title "Parent " and other with "TableEdit", but for some reason when I get WinList they are shown as 2 processes each. ( see attached image)
      Since my most important motive is to modify table data in 'TableEdit' I try to access the table in it
      My code snippet is 
      ***********************************************************************************************
      $searchString = "TableEdit"
      Local $aList = WinList("[REGEXPTITLE:(?i)(.*Internet Explorer.*)]")
      _ArrayDisplay($aList)
      For $i = 1 To $aList[0][0]
          If $aList[$i][0] <> "" And BitAND(WinGetState($aList[$i][1]), 2) Then
              ;MsgBox($MB_SYSTEMMODAL, "", "Title: " & $aList[$i][0] & @CRLF & "Handle: " & $aList[$i][1])
              If 0 <> StringInStr($aList[$i][0],"TableEdit") Then
                  $objEditIE = _IEAttach ($aList[$i][1])
                  ExitLoop
              EndIf
          EndIf
      Next
      WinActivate($objEditIE)
      $oPageContentListFrame = _IEFrameGetObjByName($objEditIE, "iframe_1")
      $iNumFrames = @extended
      MsgBox(0,"Got pagecontent",@error) ; returns 3, indicating invalid data type
      MsgBox(0,"Number of Frame",$iNumFrames) ; returns 1, expected value is 1 
      ***********************************************************************************************
      and If I do code as below the return value is different
      $searchString = "TableEdit"
       $objEditIE = _IEAttach ($searchString, "title")
      WinActivate($objEditIE)
      $oPageContentListFrame = _IEFrameGetObjByName($objEditIE, "iframe_1")
      $iNumFrames = @extended
      MsgBox(0,"Got pagecontent",@error) ; returns 0
      MsgBox(0,"Number of Frame",$iNumFrames) ; returns 0. expected value is 1
      ***********************************************************************************************
      What is wrong with my code? 
      Why do I see two process each for IE for each window?
       
      WinListImage.bmp
    • MakzNovice
      By MakzNovice
      I am using FF.au3, Since its proprietary I can't share image or link for the data I am using.
      But here is my problem abstract code .
      ; Test if I get table contents correctly
      ;$sCurr= _FFXPath("/html/body/form[1]/div[2]/div[3]/div[2]/table[@id='bodyTable']/tbody/tr[3]/td[4]", "textContent")
      ;MsgBox(0, "Current Value ", $sCurr, 2) ; output " -254.4"
      $sObj = _FFXPath("/html/body/form[1]/div[2]/div[3]/div[2]/table[@id='bodyTable']/tbody/tr[3]/td[4]")
      MsgBox(0, "Object", $sObj, 2) ; output "OBJECT|FFau3.xpath"
      $sRet = _FFObj($sObj, "value", "-253.4")
      MsgBox(0, "Return Value", $sRet); output " -253.4"
      $s = _FFXPath("/html/body/form[1]/div[2]/div[3]/div[2]/table[@id='bodyTable']/tbody/tr[3]/td[4]", "textContent")
      MsgBox(0, "New Value", $s); output " -254.4"
      My expectation is that that last MsgBox shows new value that I had set that is "-253.4"
      I would highly appreciate any support on this
       
    • Tippex
      By Tippex
      I have a problem trying to use _IEAttach to recover control after a Windows Explorer reset (e.g. on Windows 7), since all the 
      InternetExplorer.Application objects appear to be destroyed by this event. An example of this is when a PC has some kind of fault causing a pop-up error message "Windows Explorer has stopped working". I can simulate this event by using Windows Task Manager to end the Explorer.exe process then to file, new task (run...) Explorer.exe
      After this event, _IEAttach gives an @error of: 
      7 ($_IEStatus_NoMatch) - No Match
      However, using WinList() followed by WinGetText() I can recover the URL for an IE session that has lost its 
      InternetExplorer.Application object which could be used to _IECreate a new session (the $iTryAttach fails) and WinKill() the original session but the result is a if a refresh had been done (any form entries are lost) . Unfortunately form entries do not appear as text or hidden text to Windows so I'm looking for the best way to read the contents of an Internet Explorer screen (even if just text without structure). 
      When there is no InternetExplorer.Application object (because of some Windows fault) but still with an Internet Explorer session running, I tried to read its contents by a "Select All" & "Copy to Clipboard" but its form entries are blanked and combo boxes choices are all displayed with no way of finding out which ones were selected.
      Local $ClipBoardSave = _ClipBoard_GetData() ;not ClipGet() which is text only ClipPut("") ;Clear User's Clipboard Local $sText = "" Local $hWnd = WinActivate("Window Title", "") If IsHWnd($hWnd) Then Local $bStatusCtrlSend = ControlSend("Window Title", "", "", "^a^c") If $bStatusCtrlSend Then Local $bStatusCtrlClick = ControlClick("Window Title", "", "") If $bStatusCtrlClick Then $sText = ClipGet() _ClipBoard_SetData($ClipBoardSave) ;not ClipPut($ClipBoardSave) which is text only  
      Is  there a solution to this please?
×