sleep100 Posted December 18, 2013 Share Posted December 18, 2013 Hi all My previous post hasn't been very popular... lol Another issue... : I'm trying to monitor if and when the url in the browser changes.. My first au3 code... I feel so stupid, sorry lol Ops... #include <IE.au3> $oIE = _IECreate("http://www.autoitscript.com/site/") $Present_URL = "" $Previous_URL = "http://www.autoitscript.com/site/" For $i = 1 To 48000 Step 1 $Present_URL = $oIE.LocationURL If $Previous_URL = $Present_URL Then Sleep(500) Else MsgBox(0, "URL Changed!", $Present_URL) ExitLoop EndIf Next What do You think? Is there a better (I'm sure) and more light and intelligent way to do it? Any comment/help is appreciated Excuse me but these are my very first steps with the language... Have a beautiful day Link to comment Share on other sites More sharing options...
Terenz Posted December 18, 2013 Share Posted December 18, 2013 Try this: #include <IE.au3> $Present_URL = "" $Previous_URL = "http://www.autoitscript.com/site/" $oIE = _IECreate($Previous_URL) $hWnd = _IEPropertyGet($oIE, "hwnd") WinSetState($hWnd, "", @SW_MAXIMIZE) While IsHWnd($hWnd) $Present_URL = $oIE.LocationURL If $Previous_URL <> $Present_URL And $Present_URL <> "" Then MsgBox(0, "URL Changed!", $Present_URL) $Previous_URL = $Present_URL EndIf Sleep(100) WEnd Nothing is so strong as gentleness. Nothing is so gentle as real strength Link to comment Share on other sites More sharing options...
sleep100 Posted December 18, 2013 Author Share Posted December 18, 2013 Hi Terenz, thank You very much for your kind answer and Your time. And, of course, please to meet You And thank You for You (improved and elegant) code. I've tested it and it, of course, is perfect. Even if the memory usage is a little (very little! ) higher than my stupid and primitive example. Your beautiful example seems to suggest to me that my concept, at present, seems to be right, unluckily We can manage/monitor, at present, "dinamically" some (or a lot of) IE linked actions, or user actions, events, changes, webpages or behaviours. But with tricky (or sometimes enough complex) ways. Excuse me if You think that I write stupid things and excuse me for my english , I'm not a native speaker See You! And have a beautiful day Link to comment Share on other sites More sharing options...
sleep100 Posted December 19, 2013 Author Share Posted December 19, 2013 -- UPDATE -- Hi again Terenz, Hi all I have modified the code because it didn't work (at least, on my opinion..) with multiple IE Tabs. If I open a new tab with a new URL I pratically "change" the URL that I am visualizing/using. Now, instead, it "seems" that it works in a different way, more accurate. You are notified if and when You change the URL that You are visualizing in (almost) real time. This is the code: #include <IE.au3> $Present_URL = "" $Previous_URL = "http://www.autoitscript.com/site/" $oIE = _IECreate($Previous_URL) $hWnd = _IEPropertyGet($oIE, "hwnd") MsgBox(0, "Present PID", $oIE.locationname) ;Sleep(500) While IsHWnd($hWnd) $oIE = _IEAttach(WinGetHandle(""),"embedded") $Present_URL = _IEPropertyGet($oIE, "locationurl") If $Previous_URL <> $Present_URL And $Present_URL <> "" Then ; And $pid <> $Present_pid MsgBox(0, "URL Changed!", $Present_URL) $Previous_URL = $Present_URL EndIf Sleep(100) WEnd But there is an issue: I receive this messages: --> IE.au3 V2.4-0 Warning from function _IEAttach, $_IEStatus_NoMatch --> IE.au3 V2.4-0 Error from function _IEPropertyGet, $_IEStatus_InvalidDataType Everything seems to work (enough) well. Uhmm... But I don't understand if or what I am doing wrong, I'm sorry Can maybe anyone share with me his point of view? Any comment would be appreciated Thanks to everyone! Link to comment Share on other sites More sharing options...
sleep100 Posted December 19, 2013 Author Share Posted December 19, 2013 -- UPDATE -- New code: Without Errors or Warnings (I hope.. ) You can Open/Close Tabs and navigate. It seems to work in a decent way. ;#AutoIt3Wrapper_Run_Debug_Mode #include <IE.au3> $Present_URL = "" $Previous_URL = "http://www.autoitscript.com/site/" ;MsgBox(0, "1", "") $oIE = _IECreate($Previous_URL) $hWnd = _IEPropertyGet($oIE, "hwnd") ;MsgBox(0, "2", "") While IsHWnd($hWnd) $oIE = _IEAttach($hWnd,"embedded") $Present_URL = _IEPropertyGet($oIE, "locationurl") ;MsgBox(0, "4", "") If $Previous_URL <> $Present_URL And $Present_URL <> "" Then ConsoleWrite($Present_URL & @CRLF) $Previous_URL = $Present_URL EndIf Sleep(100) WEnd But there is (at least) 1 problem, still, until now If I load "heavy" websites, or if I close the Tab before the webpage is fully loaded then I usually have this error : (2705) : ==> The requested action with this object has failed.: Return SetError($_IEStatus_Success, 0, $o_object.location.href()) Test: - Open a new Tab - google for something like " best architecture websites " and navigate to some heavy webpage. - If You don't receive the error then close the Tab before the webpage is fully loaded I usually receive the error, in this case Any comment/help is welcome! PS: Excuse me if I bother You with these "low level" issues, I'm sorry Link to comment Share on other sites More sharing options...
sleep100 Posted December 19, 2013 Author Share Posted December 19, 2013 Uhmm... At present I have improved (a lot) the situation simply changing the timing of the "While". From : Sleep(100) to Sleep(500) But I would be very curious to know what is (was) the cause of the problem. The: " Return SetError($_IEStatus_Success, 0, $o_object.location.href()) " If anyone could help a poor novice like me to understand I would be very happy Thx! Link to comment Share on other sites More sharing options...
Danp2 Posted December 19, 2013 Share Posted December 19, 2013 Can you explain the need for this line? $oIE = _IEAttach($hWnd,"embedded") FYI, I believe that you should be good to go once the value of $oIE is initially set. No need to constantly retrieve the IE object as long as your intention is to monitor a single tab. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
sleep100 Posted December 20, 2013 Author Share Posted December 20, 2013 Hi Danp2 Thank You for Your kind answer And thank You for Your interest in my sloppy code lol If my memory serves me well... : I had decided to try to use the _IEAttach() because, if I haven't done big mistakes testing it, the previous code didn't manage multi-Tabs or other kind of events, like to open a new tab, to navigate with different tabs, to change Tab, etc etc... I had (quickly) read this old discussion, about problems with IE Tabs: '?do=embed' frameborder='0' data-embedContent>> However, probably, I have to read it again more carefully. You have written: "No need to constantly retrieve the IE object.." And, yes, I think so too... It was a little strange in my opinion too. However, even if with some problem, it worked with Multi-Tab browsing... So I was a little confused about this strange behaviour.. So that, help me to understand, if possible, of course.. Should I use _IEAttach() in a different way? Or to change the code and the point of view and to manage the problem in a different way? Don't worry, I'm not looking for someone who writes all the code for me Even if, sometimes, it would be beautiful, of course LOL I prefer to learn and to understand. And/or maybe some useful example, if possible, to help me to learn and to understand Thank You for everything Link to comment Share on other sites More sharing options...
Danp2 Posted December 20, 2013 Share Posted December 20, 2013 First step would be to better define the desired outcome. Are you trying to monitor the URL for a single tab, all tabs, the active tab, or ??? Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
sleep100 Posted December 20, 2013 Author Share Posted December 20, 2013 Hi Danp2 Thank You again! Desired outcome: - To monitor when I visualize (or maybe when I "Try" to visualize ) an URL. - To monitor all the URLs visualized with IE , but not only in the 1st Tab, or the 2nd, etc etc... - To monitor the URL that is visualized in the browser "in this moment". (= to know when I change the Tab or I close one Tab, etc etc..) - To monitor the URLs in a progressive way and in (almost) real time: I open the browser = https://www.google.com - Then I go to amazon.com on the 1st Tab = http://www.amazon.com Then I open a new tab, so this would happen on the 2nd Tab... = about:Tabs Then, always on the 2nd Tab, I go to https://news.google.com/ = https://news.google.com/ Then, here, on the 2nd Tab I click a link to read an article, so that a new Tab will be opened (3rd Tab) = http://www.myarticle.com Now, I stop reading for a while, I go back to the 1st Tab = http://www.amazon.com Now again back to read the article on the 3rd Tab = http://www.myarticle.com Now I close the 3rd Tab (so I will visualize the last Tab for my IE settings, the 2nd Tab) = https://news.google.com/ and so on... I hope that You could understand something more about the goal, with my little and crazy example... lol Link to comment Share on other sites More sharing options...
Danp2 Posted December 20, 2013 Share Posted December 20, 2013 What will you be doing with this data, assuming that you can capture it? Does the script need to take some action when it identifies a URL change? FWIW, you can get the active IE tab with the following code: ; get first IE instance $oIE = _IEAttach ("", "instance", 1) If @error = $_IEStatus_Success Then ; get window title $hwnd = _IEPropertyGet($oIE, "hwnd") $title = WinGetTitle($hwnd) $oIE = _IEAttach($title, "windowtitle") EndIf Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
sleep100 Posted December 20, 2013 Author Share Posted December 20, 2013 Hi Damp2 Thank You for Your suggestion. I will try to use and to think of it when I will have a little of free time But... I was thinking... and if You have more Tabs with the same title? Could it be a problem...? Uhmm.. However... I will see it.. About Your question(s): I like the crazy idea to try to develop a kind of GUI to navigate the web. I like the crazy idea that this GUI could be "customized" (maybe by someone for someone else, to help him/her for a better, quicker and simpler experience) or perhaps also "customizable" by the user himself. So You can understand my interest, at present, in URLs and other kind of data. I know that my (few) skills, at present, are not appropriate for such a thing. But I usually think... If You don't start You will never finish, so... here I am.. to waste Your days with my miserable coding and questions.. Have a nice day! 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