Sign in to follow this  
Followers 0
Shinies

Embedding IE

9 posts in this topic

#1 ·  Posted (edited)

I haven't got any replies so i figured my question was either not worded well or i didn't give an example that you guys could use. So here is the example: cannot backspace in the edit after having clicked in the embedded IE control. How do i either avoid this or take measures to correct for this?

;==========================================================================================
#include <ie.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiEdit.au3>


;Mainwindow
$WinMain = GUICreate("hello", 510, 510)
$MainMsgBoardInput = _GUICtrlEdit_Create($WinMain, "", 1, 439, 498, 50, BitOR($ES_MULTILINE, $ES_WANTRETURN, $WS_VSCROLL, $ES_AUTOVSCROLL))
$oMainIE = _IECreateEmbedded()
GUICtrlCreateObj($oMainIE, 1, 1, 498, 435)

_IENavigate($oMainIE, "about:blank")

;Perform starup operations
GUISetState(@SW_SHOW)

While 1

$mMsg = GUIGetMsg()
Switch $mMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch

WEnd
Edited by Smerk

Share this post


Link to post
Share on other sites



First, please include functional code.. I had to figure out what includes to use..

Second, I found that it is same behavior with _GUICtrlRichEdit_Create

Third, If you use GUICtrlCreateEdit, you can backspace, but you lose your cursor () which is something I am waiting to hear back on.

;==========================================================================================
#include <ie.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiEdit.au3>
;Mainwindow
$WinMain = GUICreate("hello", 510, 510)
$MainMsgBoardInput = GUICtrlCreateEdit( "", 1, 439, 498, 50, BitOR($ES_MULTILINE, $ES_WANTRETURN, $WS_VSCROLL, $ES_AUTOVSCROLL))
$oMainIE = _IECreateEmbedded()
GUICtrlCreateObj($oMainIE, 1, 1, 498, 435)
_IENavigate($oMainIE, "about:blank")
;Perform starup operations
GUISetState(@SW_SHOW)
While 1
$mMsg = GUIGetMsg()
Switch $mMsg
Case -3
Exit
EndSwitch
WEnd

Share this post


Link to post
Share on other sites

First, please include functional code.. I had to figure out what includes to use..

Second, I found that it is same behavior with _GUICtrlRichEdit_Create

Third, If you use GUICtrlCreateEdit, you can backspace, but you lose your cursor () which is something I am waiting to hear back on.

That's pretty odd. I have no clue why i lost the includes when i pasted the code in, i actually had no clue what you were talking about until i double checked. Sorry about that, and thank you for the reply.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Try this, I borrow this _GUICtrlEdit_SetPos function from Yashied --

;==========================================================================================
#include <ie.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiEdit.au3>
#Include <ScrollBarConstants.au3>
;Mainwindow
$WinMain = GUICreate("hello", 510, 510)
$MainMsgBoardInput = _GUICtrlEdit_Create($winmain, "", 1, 439, 498, 50, BitOR($ES_MULTILINE, $ES_WANTRETURN, $WS_VSCROLL, $ES_AUTOVSCROLL))
$oMainIE = _IECreateEmbedded()
GUICtrlCreateObj($oMainIE, 1, 1, 498, 435)
$backspace = GUICtrlCreateDummy()
Dim $AccelKeys[1][2] = [["{BACKSPACE}", $backspace]]
GUISetAccelerators($AccelKeys,$winmain)
_IENavigate($oMainIE, "about:blank")
;Perform starup operations
GUISetState(@SW_SHOW)
While 1
$mMsg = GUIGetMsg()
Switch $mMsg
Case $backspace
$out = _GUICtrlEdit_GetText($MainMsgBoardInput)
_GUICtrlEdit_SetText($MainMsgBoardInput,StringTrimRight($out,1))
_GUICtrlEdit_SetPos($MainMsgBoardInput, -1, -1)
Case -3
Exit
EndSwitch
WEnd
;http://www.autoitscript.com/forum/topic/124099-howto-get-cursor-position-in-multiline-edit/
; #FUNCTION# ====================================================================================================================
; Name...........: _GUICtrlEdit_SetPos
; Description....: Sets the caret to the specified line and column.
; Syntax.........: _GUICtrlEdit_SetPos ( $hWnd, $iLine [, $iColumn] )
; Parameters.....: $hWnd - Handle or identifier (controlID) to the control.
;                $iLine - The zero-based index of the line on which must set the caret. If this parameter is (-1),
;                            the caret will be set on the last line.
;                $iColumn - The zero-based index of the column on which must set the caret. If this parameter is (-1),
;                            the caret will be set at the end of the specified line. Default is 0.
; Return values..: Success - 1.
;                Failure - 0 and sets the @error flag to non-zero.
; Author.........: Yashied
; Modified.......:
; Remarks........: None
; Related........: _GUICtrlEdit_Scroll(), _GUICtrlEdit_SetSel()
; Link...........: None
; Example........: Yes
; ===============================================================================================================================
Func _GUICtrlEdit_SetPos($hWnd, $iLine, $iColumn = 0)
If Not IsHWnd($hWnd) Then
     $hWnd = GUICtrlGetHandle($hWnd)
     If $hWnd = 0 Then
         Return SetError(1, 0, 0)
     EndIf
EndIf
Local $Lenght, $Num = 0, $Count = _GUICtrlEdit_GetLineCount($hWnd)
If $iLine > $Count - 1 Then
     $Num = _GUICtrlEdit_GetTextLen($hWnd)
Else
     If $iLine < 0 Then
         $iLine = $Count - 1
     EndIf
     For $i = 0 To $iLine - 1
         $Num += _GUICtrlEdit_LineLength($hWnd, $i) + 2 ; + @CR + @LF
     Next
     $Lenght = _GUICtrlEdit_LineLength($hWnd, $iLine)
     If ($iColumn < 0) Or ($iColumn > $Lenght) Then
         $iColumn = $Lenght
     EndIf
     $Num += $iColumn
EndIf
_GUICtrlEdit_SetSel($hWnd, $Num, $Num)
_GUICtrlEdit_Scroll($hWnd, $SB_SCROLLCARET)
Return 1
EndFunc ;==>_GUICtrlEdit_SetPos
Edited by step887

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Good thinking mate! However in that script pressing backspace would delete content from the edit control no matter where the input was focused. Ive made a slight change so that it only deletes from the control if the control is selected, otherwise it will not.

There are quite possibly some other issue that will continue to arise from the embedded IE, so it may be more simple to use the native edit control rather than the UDF version.

Heres the code for anyone else who might run into this problem though:

EIDT: Cut off my damn includes again, lol! Whats up with that...

;==========================================================================================
#include <ie.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiEdit.au3>
#Include <ScrollBarConstants.au3>
#include <WinAPI.au3>
;Mainwindow
$WinMain = GUICreate("hello", 510, 510)
$MainMsgBoardInput = _GUICtrlEdit_Create($winmain, "", 1, 439, 498, 50, BitOR($ES_MULTILINE, $ES_WANTRETURN, $WS_VSCROLL, $ES_AUTOVSCROLL))
$oMainIE = _IECreateEmbedded()
GUICtrlCreateObj($oMainIE, 1, 1, 498, 435)
$backspace = GUICtrlCreateDummy()
Dim $AccelKeys[1][2] = [["{BACKSPACE}", $backspace]]
GUISetAccelerators($AccelKeys,$winmain)
_IENavigate($oMainIE, "about:blank")
;Perform starup operations
GUISetState(@SW_SHOW)
While 1
$mMsg = GUIGetMsg()
Switch $mMsg

Case $backspace
If _WinAPI_GetFocus() = $MainMsgBoardInput Then
$out = _GUICtrlEdit_GetText($MainMsgBoardInput)
_GUICtrlEdit_SetText($MainMsgBoardInput,StringTrimRight($out,1))
_GUICtrlEdit_SetPos($MainMsgBoardInput, -1, -1)
EndIf

Case -3
Exit
EndSwitch
WEnd
;http://www.autoitscript.com/forum/topic/124099-howto-get-cursor-position-in-multiline-edit/
; #FUNCTION# ====================================================================================================================
; Name...........: _GUICtrlEdit_SetPos
; Description....: Sets the caret to the specified line and column.
; Syntax.........: _GUICtrlEdit_SetPos ( $hWnd, $iLine [, $iColumn] )
; Parameters.....: $hWnd - Handle or identifier (controlID) to the control.
; $iLine - The zero-based index of the line on which must set the caret. If this parameter is (-1),
; the caret will be set on the last line.
; $iColumn - The zero-based index of the column on which must set the caret. If this parameter is (-1),
; the caret will be set at the end of the specified line. Default is 0.
; Return values..: Success - 1.
; Failure - 0 and sets the @error flag to non-zero.
; Author.........: Yashied
; Modified.......:
; Remarks........: None
; Related........: _GUICtrlEdit_Scroll(), _GUICtrlEdit_SetSel()
; Link...........: None
; Example........: Yes
; ===============================================================================================================================
Func _GUICtrlEdit_SetPos($hWnd, $iLine, $iColumn = 0)
If Not IsHWnd($hWnd) Then
$hWnd = GUICtrlGetHandle($hWnd)
If $hWnd = 0 Then
Return SetError(1, 0, 0)
EndIf
EndIf
Local $Lenght, $Num = 0, $Count = _GUICtrlEdit_GetLineCount($hWnd)
If $iLine > $Count - 1 Then
$Num = _GUICtrlEdit_GetTextLen($hWnd)
Else
If $iLine < 0 Then
$iLine = $Count - 1
EndIf
For $i = 0 To $iLine - 1
$Num += _GUICtrlEdit_LineLength($hWnd, $i) + 2 ; + @CR + @LF
Next
$Lenght = _GUICtrlEdit_LineLength($hWnd, $iLine)
If ($iColumn < 0) Or ($iColumn > $Lenght) Then
$iColumn = $Lenght
EndIf
$Num += $iColumn
EndIf
_GUICtrlEdit_SetSel($hWnd, $Num, $Num)
_GUICtrlEdit_Scroll($hWnd, $SB_SCROLLCARET)
Return 1
EndFunc ;==>_GUICtrlEdit_SetPos
Edited by Smerk

Share this post


Link to post
Share on other sites

See my sig for an alternative to embedded IE created by another user. It works well.

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

Dale from some of my previous testing before posting, using that UDF caused the embedded window to lose visibility when another child window is placed over it. Did not find out how to get around that problem.

Share this post


Link to post
Share on other sites

There are long-standing issues with GUIControlCreateObject and keyboard events and visibility. If the suggested workaround doesn't work for you, I'd suggest looking through the Trac tickets and opening a new one if your issue is not called out.

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

Understood, thank you for the help Dale :)

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  
Followers 0

  • Similar Content

    • Spask
      By Spask
      Hi, I'm trying to find a text value inside of a html.
      This is what the line looks like normally:
      <p id="line1" class> <span class="bot">TEXT HERE</span> </p> The text then changes to a non breaking space:
      <p id="line1" class> <span class="bot">&nbsp;</span> </p> And then it changes back to normal text but it's different every time.
      Can I code this so that it grabs the text every time it changes and has a variable that represents it?
      I currently have this inside of my loop:
      $span = .document.getElementsByTagName("span") For $text In $span If $text.value = "&nbsp;" Then Sleep(50) MsgBox(0,0,0) ;messagebox to test if it can be found, but I don't know how to grab the text EndIf Next The problem is that there are many other lines in the html that have the same span but are called "line3", "line5", etc and the one I need is from "line1".
      I will appreciate if anyone can help with this!
    • electrons
      By electrons
      hi  , hope  you all doing well 
       cant find any elements on the page ?  and the right click mouse dont work too?
      iam trying with more than method , i need help please!!
       

    • ur
      By ur
      I have kept below line to wait for IE to load the site completely and continue.
      _IELoadWait($oIE)
       
      But, the code is continuing without waiting for it and I my execution is failing as the elements are not loaded completely.

       
      Any suggestions for alternate code to wait for the browser to load completely?
       
    • ur
      By ur
      We can select elements in IE using their IDs as below.
      Local $oDiv = _IEGetObjById($oIE, "x-auto-16-input") But to one button in the webpage, there is no ID to it.
      In selenium we have option to select this element using the CssSelector and clicked the button using below code in c# selenium.
      driver.FindElement(By.CssSelector("button.x-btn-text")).Click(); What is the alternative for this in AUtoIT?
    • FrancescoDiMuro
      By FrancescoDiMuro
      Good morning everyone
      I worked a bit on a little project of mine, and I managed to do what I was trying to do, or, automate a quiz in AutoIt.
      Now, everything works fine but, in order to achieve what I'm trying to achive, I'd like to make this script run faster.
      I'll attach a portion of the code in order to let you understand what my script does.
      $objIE_h1 = _IETagNameGetCollection($objIE, "h1") ; Take the text of the answer If @error Then ConsoleWrite("Errore durante la lettura degli h1 nella pagina. - Errore: " & @error & @CRLF) Else For $objElement In $objIE_h1 $strInnerText = $objElement.innerText Next Select Case StringInStr($strInnerText, "QUESTION") ; Here is the question ; PS4 PRO $objSpans = _IETagNameGetCollection($objIE, "span") ; Answers are stored here For $objElement In $objSpans If $i >= 4 Then $strAnswer = $objElement.innerText ; Take the text of the answer n° 0, 1, 2, 3 If StringInStr($strAnswer, "CORRECT ANSWER") Then ; If I match the correct answer, then, I have to click on the input with answer id = answer_i $j = $i - 4 $objInput = _IEGetObjById($objIE, "answer_" & $j) If @error Then ConsoleWrite("Errore durante la lettura della risposta #" & $i & " - Errore: " & @error & @CRLF) Else _IEAction($objInput, "click") If @error Then ConsoleWrite("Errore durante il click sull'elemento. - Errore: " & @error) Else ConsoleWrite($j & ") Risposta: " & $strAnswer & @CRLF) ExitLoop EndIf EndIf EndIf $i+=1 Else $i+=1 EndIf Next $i = 0 $j = 0 This is what my script does.
      Questions are 20, in which I have 15 multiple choice question, 2 images ( on which I use _IEImgClick() ), and 3 text inputs ( a simple send with the text I have to enter ).
      How can I make all of these, faster?
      If I reach this goal, I've probably done one of my best goals in life, and I'd like to share my happiness with you, giving a huge donation to this fantastic community!
      Thanks for your help