Jump to content
Sign in to follow this  
MakzNovice

How to get Control back of parent browser

Recommended Posts

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

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

@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
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

@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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Mariog2000
      I've tried for a few days to simply open a url in IE and click an IE object that I can't "TAB" to and don't want to use a mouse-click if at all possible.  I've read up on things like using IEAction and IETagNameGetCollection to find the object but not smart enough to figure out how that works with my url or how to tell if my url is "basic" or a "form", "frameset", "iframe", etc.
      The other problem is I've tried using the "Run" and "ShellExecute" commands to open the browser, which works, but it opens it in a way that doesn't include my currently logged in user account.  For example, if I just click IE or Chrome for that matter and open my default homepage of google, the page that opens knows I'm logged in.  When I use "Send" "ShellExecute" or "_IE_Create" they always open pages generically which would require a login.
      So questions are, if I have a URL I'm trying to open, that's passes the currently logged on users credentials when opening the page (no clue where that happens)
      1.  Are there any code examples someone is willing to share that opens my IE maximized, with logged in credentials, and
      2.  Once that works, can someone suggest a technique a non-developer can find which IE Objects I need to send a "click" to so it opens the correct menu, pop-up, url, etc., associated with that object.  I've copied what doesn't work and sure I'm way off but it's not for a lack of effort. I'll keep trying and post updates but not looking good 🙂
      #include <IE.au3>
      Call ("selection")
      Func selection ()
      Global $oIE = _IECreate ("https://internal-webpage.aspx")
      Local $selectid = _IEGetObjByName ($oIE, "signageNo")
      Local $button = _IEGetObjByName ($oIE, "GO")

      _IEFormElementOptionSelect ($selectid, "3")
      _IEAction ($button,"click")
      EndFunc
      #include <IE.au3> Call ("selection") Func selection () Global $oIE = _IECreate ("https://internal-webpage.aspx") Local $selectid = _IEGetObjByName ($oIE, "signageNo") Local $button = _IEGetObjByName ($oIE, "GO") _IEFormElementOptionSelect ($selectid, "3") _IEAction ($button,"click") EndFunc 1. 
    • By zuladabef
      I want to set the value of a input, but I only have the input name and input id.  I cannot find a form in the source.  Form collection does not return any results.  
      Is there a way to use FormElementSetValue without a form name? Can I use _IEGetObjByName or _IEGetObjById?  If so, how do I set the value once I have the object? Where do I go from here? Local $oIE = _IEAttach("[Website Goes Here"]) Local $oForm = _IEFormGetCollection($oIE, 1) Local $oQuery = _IEFormElementGetCollection($oForm, 4) _IEFormElementSetValue($oQuery, "Set it to this")  
    • By Seminko
      Hey there,
      below function returns an "object collection" (not sure if that's the correct term) of 'a' elements grabbed from within //*[@id="J_DetailMeta"].
      However, I need the returned collection not to include objects with 'aria-disabled = true'. Is there a way of removing specific objects from such a collection?
      Func GetObjectList($sPicker) $oDetailMeta = _IEGetObjById($oIE, "J_DetailMeta") If Not @error Then $tags = $oDetailMeta.GetElementsByTagName("ul") For $tag in $tags $data_ID_value = $tag.GetAttribute("data-property") If $sPicker = "color" Then If $data_ID_value = '????' Or $data_ID_value = "????" Then $oReturnList = $tag.GetElementsByTagName("a") EndIf ElseIf $sPicker = "network" Then If $data_ID_value = '????' Then $oReturnList = $tag.GetElementsByTagName("a") EndIf ElseIf $sPicker = "storage" Then If $data_ID_value = '????' Then $oReturnList = $tag.GetElementsByTagName("a") EndIf EndIf Next EndIf Return $oReturnList EndFunc $oColorList = GetObjectList("color") For $oColor In $oColorList If StringInStr($oColor.GetAttribute("aria-disabled"), "true") <= 0 Then ; remove object from the collection ??? EndIf Next  
    • By nooneclose
      my FF.au3 does get included but my script does not open firefox. 
      here is my code so far:
      #include <FF.au3> _FFStart("https://www.google.com", Default, 0) I am using firefox portable version 52.0 Any and all help would be greatly appreciated.  
      The code runs but nothing happens. I think the FF.au3 cannot find or connect to the firefox portable.  
    • By careca
      Hi, i feel im close to getting it to work, but there must be something im missing that's probably easy for you experts.
      #include <IE.au3> #include <File.au3> #include <MsgBoxConstants.au3> $Visible = 1 Local $oIE $oIE = _IECreate("https://beemp3s.net/mp3-download.html", 0, $Visible, 1, 1) _IELoadWait($oIE) If $oIE <> @error Then ;_ArrayText() _QuerySite('Finding Hope - Without You') ;_IEQuit($oIE) ;Exit Else MsgBox(64 + 262144, 'Fail', 'Could not create a new window') EndIf ;============================================================================= Func _QuerySite($Name) Local $oIE_ObjectToSearch = _IEGetObjById($oIE, 'query') _IEDocInsertText($oIE_ObjectToSearch, $Name) Local $oIE_ObjectToClick = _IEGetObjById($oIE, "search-action") _IEAction($oIE_ObjectToClick, 'click') _IELoadWait($oIE, 2000) ;============================================================================= Local $oSubmitClick = _IEGetObjById($oIE, "col-md-12") _IEAction($oSubmitClick, "click") _IELoadWait($oIE, 2000) ;============================================================================= Local $oBtns = _IETagNameGetCollection($oIE, "div") For $oBtn In $oBtns If String($oBtn.classname) = "col-md-12" Then If String($oBtn.innertext) = "Download / Play" Then ConsoleWrite($oBtn.innertext & @CRLF) _IEAction($oBtn, 'click') EndIf EndIf Next ;============================================================================= ;Local $oElements = _IETagNameAllGetCollection($oIE) ;For $oElement In $oElements ; If $oElement.id Then MsgBox($MB_SYSTEMMODAL, "Element Info", "Tagname: " & $oElement.tagname & @CRLF & "id: " & $oElement.id & @CRLF & "innerText: " & $oElement.innerText) ;Next ;============================================================================= ;_IEQuit($oIE) ;Exit ;============================================================================= EndFunc ;==>_QuerySite ;============================================================================= Func _ArrayText() If FileExists('Titles.txt') Then Local $FO = FileOpen('Titles.txt') Local $R2A = FileReadToArray($FO) Local $iLineCount = @extended FileClose($FO) For $f = 0 To $iLineCount - 1 ConsoleWrite($f & ' - ' & $R2A[$f] & @CRLF) _QuerySite($R2A[$f]) Next Else MsgBox(64 + 262144, 'Fail', 'Could not find the file Titles.txt') EndIf EndFunc ;==>_ArrayText ;============================================================================= The idea is to get into this site, write into the search and click, which i did, but now the problem is clicking in any of the buttons in the results page, im looking for a way to click the first one, it always matches to what i want, so no need to fiddle around.
      Site
      Thanks for help in advance.

×
×
  • Create New...