prodesigner Posted July 30, 2019 Share Posted July 30, 2019 I am trying to focus IE, then to navigate to a web page in existing IE window (same tab), and add text to fields. Here is what I have so far: #include <IE.au3> Global $website_link = "https://www.google.com/" Global $TextToAdd = "Hello there" Global $IEpath = "C:\Program Files\Internet Explorer\iexplore.exe" If WinActivate("[CLASS:IEFrame]") Then WinSetState("[CLASS:IEFrame]", "", @SW_MAXIMIZE) Else Run ($IEpath , "" , @SW_SHOWMAXIMIZED) EndIf $oie = _IEAttach(WinGetHandle("[Active]"), "hwnd") If @error Then Run ($IEpath , "" , @SW_SHOWMAXIMIZED) EndIf _IENavigate($oie, $website_link) sleep(1000) Global $oTitle = _IEGetObjByName($oIE, "q") _IEFormElementSetValue($oTitle, $TextToAdd) Exit It works a few times then I trigger something (minimized IE, not active, not started etc.) and it doesn't work even if I exit and start the script again. Here is the error message that I am getting: Quote Line 272 (File "C:\Program Files (x86)\AutoIt3\Include\IE.au3"): $oObject.navigate($sUrl) $oObject^ ERROR Error: The requested action with this object has failed. Help with this code or a new solution would be very helpful. Link to comment Share on other sites More sharing options...
Nine Posted July 30, 2019 Share Posted July 30, 2019 Here how I would do it using more of the _IE #include <Constants.au3> #include <IE.au3> Opt ("MustDeclareVars", 1) Global $website_link = "https://www.google.com/" Global $TextToAdd = "Hello there", $oIE $oIE = _IECreate ("about:blank", 1) If @error Then Exit MsgBox ($MB_SYSTEMMODAL,"","Error creating/attaching IE") Global $hWnd = _IEPropertyGet ($oIE, "hwnd") If @error Or Not IsHWnd ($hWnd) then Exit MsgBox ($MB_SYSTEMMODAL,"","Error getting hwnd") WinSetState($hWnd, "", @SW_MAXIMIZE) WinActivate($hWnd) WinWaitActive($hWnd) _IENavigate($oIE, $website_link) If @error Then Exit MsgBox ($MB_SYSTEMMODAL,"","Error navigating IE") Global $oTitle = _IEGetObjByName($oIE, "q") _IEFormElementSetValue($oTitle, $TextToAdd) “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
prodesigner Posted July 30, 2019 Author Share Posted July 30, 2019 Thanks Nine, This line is my "problem", I need to use existing open Internet explorer to open a web page. $oIE = _IECreate ("about:blank", 1) My script adds posts to wordpress website and whenever I run the script it opens new IE window which is not acceptable for my project. Link to comment Share on other sites More sharing options...
Nine Posted July 30, 2019 Share Posted July 30, 2019 20 minutes ago, prodesigner said: This line is my "problem", I need to use existing open Internet explorer to open a web page. The number 1 after url is a TryToAttach. So if an instance of IE exists it will attach instead of creating a new... “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
prodesigner Posted July 30, 2019 Author Share Posted July 30, 2019 Unfortunately it's not recognizing that IE is already open, I found similar experiences here on forums. Link to comment Share on other sites More sharing options...
Nine Posted July 30, 2019 Share Posted July 30, 2019 (edited) I see what is the problem, with the _IECreate, now try this : #include <Constants.au3> #include <IE.au3> Opt ("MustDeclareVars", 1) Global $website_link = "https://www.google.com/" Global $TextToAdd = "Hello there", $oIE Global $hWnd = WinGetHandle ("[CLASS:IEFrame]") If $hWnd Then $oIE = _IEAttach ($hWnd, "hwnd") If @error Then Exit MsgBox ($MB_SYSTEMMODAL,"","Error attaching IE") Else $oIE = _IECreate () If @error Then Exit MsgBox ($MB_SYSTEMMODAL,"","Error creating IE") $hWnd = _IEPropertyGet ($oIE, "hwnd") EndIf WinSetState($hWnd, "", @SW_MAXIMIZE) WinActivate($hWnd) WinWaitActive($hWnd) _IENavigate($oIE, $website_link) If @error Then Exit MsgBox ($MB_SYSTEMMODAL,"","Error navigating IE") Global $oTitle = _IEGetObjByName($oIE, "q") _IEFormElementSetValue($oTitle, $TextToAdd) Edited July 30, 2019 by Nine prodesigner 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
prodesigner Posted July 30, 2019 Author Share Posted July 30, 2019 Thanks again, I got it to work at first but now I am getting error" Quote Line 272 (File "C:\Program Files (x86)\AutoIt3\Include\IE.au3"): $oObject.navigate($sUrl) $oObject^ ERROR Error: The requested action with this object has failed. It's newest Autoit V3, no modifications. Used Notepad++, then Scite to save the script. Link to comment Share on other sites More sharing options...
prodesigner Posted July 30, 2019 Author Share Posted July 30, 2019 Sorry let me investigate a bit more, it looks like one of previous scripts was not closed and that caused error. Looks good so far, thanks! Link to comment Share on other sites More sharing options...
prodesigner Posted July 30, 2019 Author Share Posted July 30, 2019 I tested it, it's working good. It is very useful piece of code, I searched forums and didn't find a similar code . Thanks a lot! Link to comment Share on other sites More sharing options...
Nine Posted July 30, 2019 Share Posted July 30, 2019 Glad you like it.... “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
prodesigner Posted August 12, 2019 Author Share Posted August 12, 2019 (edited) I got a new scenario with the code provided by Nine. If I have an IE window with a file loaded from local computer (c:/sample.html), new http load will not attach to current window but it will open a new one. Is there a possibility to attach http page to local html file window? Sample HTML: <!DOCTYPE html> <html> <body> <h1>My First Heading</h1> <p>My first paragraph.</p> </body> </html> Edited August 12, 2019 by prodesigner Link to comment Share on other sites More sharing options...
prodesigner Posted August 20, 2019 Author Share Posted August 20, 2019 (edited) I am still looking for a solution to attach html file from hdd to existing IE, then to attach any www page to the same tab and repeat it x times. The problem is, it will open new window for local html file (check my previous message with a better explanation). Any advice? Edited August 20, 2019 by prodesigner Link to comment Share on other sites More sharing options...
Danp2 Posted August 20, 2019 Share Posted August 20, 2019 1 hour ago, prodesigner said: Any advice? So far, you've only told us that it doesn't work as expected. You haven't posted code showing what you've tried thus far, so it's difficult to know how to help you. 🙂 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
prodesigner Posted August 20, 2019 Author Share Posted August 20, 2019 Here is the code, sample html attached. The code bellow works good when attaching to www style links, but it is not working when attaching local html file. expandcollapse popup#include <GUIConstantsEx.au3> ; for gui #include <MsgBoxConstants.au3> ; for messages #include <IE.au3> ; for Internet Explorer Opt ("MustDeclareVars", 1) Global $hWnd = WinGetHandle ("[CLASS:IEFrame]") If $hWnd Then Global $oIE = _IEAttach ($hWnd, "hwnd") If @error Then Exit MsgBox ($MB_SYSTEMMODAL,"","Error attaching IE") Else Global $oIE = _IECreate () If @error Then Exit MsgBox ($MB_SYSTEMMODAL,"","Error creating IE2") $hWnd = _IEPropertyGet ($oIE, "hwnd") EndIf WinSetState($hWnd, "", @SW_MAXIMIZE) WinActivate($hWnd) WinWaitActive($hWnd) _IENavigate($oIE, "G:\index.html") If @error Then Exit MsgBox ($MB_SYSTEMMODAL,"","Error navigating IE3") Sleep(2000) Global $hWnd = WinGetHandle ("[CLASS:IEFrame]") If $hWnd Then Global $oIE = _IEAttach ($hWnd, "hwnd") If @error Then Exit MsgBox ($MB_SYSTEMMODAL,"","Error attaching IE") Else Global $oIE = _IECreate () If @error Then Exit MsgBox ($MB_SYSTEMMODAL,"","Error creating IE2") $hWnd = _IEPropertyGet ($oIE, "hwnd") EndIf WinSetState($hWnd, "", @SW_MAXIMIZE) WinActivate($hWnd) WinWaitActive($hWnd) _IENavigate($oIE, "https://www.autoitscript.com") If @error Then Exit MsgBox ($MB_SYSTEMMODAL,"","Error navigating IE3") Exit index.html Link to comment Share on other sites More sharing options...
Nine Posted August 20, 2019 Share Posted August 20, 2019 Works fine with me with you code and file. I trust that the path of you local html file is probably wrong. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
prodesigner Posted August 21, 2019 Author Share Posted August 21, 2019 (edited) Quote I trust that the path of you local html file is probably wrong. The path to the file is fine, actually I am working on it hours and hours already, not just today. It's weird that it is working for you. I also tried a lot of other ideas from the forum and nothing worked for me. Here are some conclusions for the code from above: 1. attach www, then local html - pass 2. attach www, then www again - pass 3. attach local html, then local html again - pass 4. attach local html, then www - fail (it opens a new window, not maximized which is also a signal for something) That #4 is preventing me to repeat the whole action that includes local htmls and www web site. Edited August 21, 2019 by prodesigner Link to comment Share on other sites More sharing options...
Nine Posted August 21, 2019 Share Posted August 21, 2019 Can you run IE examples in help file ? Cause it is pretty much the same as you are trying to achieve... “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
prodesigner Posted August 21, 2019 Author Share Posted August 21, 2019 Using the first example from help files: I found something that might be wrong, apart from the same (new window) behavior like earlier I found this (image attached): file:///G:/index.html - this /// is weird to me and might be the problem. I will try all other examples too and hopefully will find out what is the problem. #include <MsgBoxConstants.au3> ; for messages #include <IE.au3> ; for Internet Explorer Opt ("MustDeclareVars", 1) Global $hWnd = WinGetHandle ("[CLASS:IEFrame]") If $hWnd Then Global $oIE = _IEAttach ($hWnd, "hwnd") If @error Then Exit MsgBox ($MB_SYSTEMMODAL,"","Error attaching IE") Else Global $oIE = _IECreate () If @error Then Exit MsgBox ($MB_SYSTEMMODAL,"","Error creating IE2") $hWnd = _IEPropertyGet ($oIE, "hwnd") EndIf WinSetState($hWnd, "", @SW_MAXIMIZE) WinActivate($hWnd) WinWaitActive($hWnd) _IENavigate($oIE, "G:\index.html") If @error Then Exit MsgBox ($MB_SYSTEMMODAL,"","Error navigating IE3") Sleep(2000) Global $oIE = _IEAttach ("HTML attach by title") MsgBox($MB_SYSTEMMODAL, "The URL", _IEPropertyGet($oIE, "locationurl")) _IENavigate($oIE, "https://www.autoitscript.com") If @error Then Exit MsgBox ($MB_SYSTEMMODAL,"","Error navigating IE3") Exit index.html Link to comment Share on other sites More sharing options...
prodesigner Posted August 21, 2019 Author Share Posted August 21, 2019 Here is the most basic example from help file and it doesn't work for me. I am trying to open www page in the same window after local html file. It usually opens www page in new window but this time it will not load it at all. Here is the error message: Quote --> IE.au3 T3.0-2 Error from function _IENavigate, $_IESTATUS_InvalidObjectType ; Create a browser window and navigate to a website, ; wait 5 seconds and navigate to another ; wait 5 seconds and navigate to another #include <IE.au3> Local $oIE = _IECreate("www.autoitscript.com") Sleep(2000) _IENavigate($oIE, "G:\index.html") Sleep(2000) _IENavigate($oIE, "http://www.autoitscript.com/forum/index.php?showforum=9") index.html Link to comment Share on other sites More sharing options...
prodesigner Posted August 21, 2019 Author Share Posted August 21, 2019 This topic helped, it was related to security. Adding "#RequireAdmin" to the top helped with attaching to the same window. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now