Sanjos Posted June 7, 2010 Share Posted June 7, 2010 Hiho guys I'm pretty new to autoit and have a question about a script. So what I try to do is: A small image is appearing randomly on a homepage. If it's there, click on it, if not, click on the link "home". Here's the script: if (isElementPresent(("//img[contains(@src,'http://img.lokalisten.de/lokiimg/lokalisten/schnitzeljagd/schnitzel.png')]")) Then click ("//img[contains(@src,'http://img.lokalisten.de/lokiimg/lokalisten/schnitzeljagd/schnitzel.png')]"))); else click ("link=home"); EndIf I'm sorry if this is a noob question but I would be thankful if u could correct it or tell me another script that works. Thank you Link to comment Share on other sites More sharing options...
kaotkbliss Posted June 7, 2010 Share Posted June 7, 2010 There is sooo much wrong here. First you need to wait until the page fully loads maybe _IELoadWait Next, checking if your image is there (link inside) _IEPropertyGet might be helpful or _INetGetSource with a StringInStr search to see if the link exists then _IEImgClick if it does exist or _IELinkClickByText if it does not. All these functions can be found in the help file And if you use the _IE functions add #include <IE.au3> to the top of your script. Also if the INet function is used add also #include <INet.au3> to the top. 010101000110100001101001011100110010000001101001011100110010000 001101101011110010010000001110011011010010110011100100001 My Android cat and mouse gamehttps://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek We're gonna need another Timmy! Link to comment Share on other sites More sharing options...
Sanjos Posted June 7, 2010 Author Share Posted June 7, 2010 ok, I got this now: #include <IE.au3> $oIE = _IECreate ("http://www.lokalisten.de/web/showHome.do") _IELoadWait ($oIE) #include <IE.au3> _IEImgClick ($oIE, "http://img.lokalisten.de/lokiimg/lokalisten/schnitzeljagd/schnitzel.png") #include <IE.au3> _IELinkClickByText ($oIE, "home") But how exactly can I get it to check for the image after the site loaded? Like: Check for image --> click image --> home --> check for image --> home etc.... Link to comment Share on other sites More sharing options...
kaotkbliss Posted June 7, 2010 Share Posted June 7, 2010 You only need the #include <IE.au3> once in your script. As for your question, maybe something like: $source=INetGetSource("http://www.lokalisten.de/web/showHome.do") $string=StringInStr($source,"schnitzel.png") If $string=0 Then IELinkClickByText ($oIE, "home") ElseIf $string<>0 Then _IEImgClick ($oIE, "http://img.lokalisten.de/lokiimg/lokalisten/schnitzeljagd/schnitzel.png") EndIf 010101000110100001101001011100110010000001101001011100110010000 001101101011110010010000001110011011010010110011100100001 My Android cat and mouse gamehttps://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek We're gonna need another Timmy! Link to comment Share on other sites More sharing options...
Sanjos Posted June 7, 2010 Author Share Posted June 7, 2010 hmm, it opens the page and clicks on home when the pic is not there. Ok, but even when it's there, it clicks on home and not on the pic. And how can I make it repeat it? Do I have to put a loop in it? Link to comment Share on other sites More sharing options...
kaotkbliss Posted June 7, 2010 Share Posted June 7, 2010 To have it repeat, yes you will have to put it in a loop. (unless you close your web page each time, do not put the _IECreate in the loop or you will end up with a new IE opening for each loop (which could end up being thousands)) Maybe StrInStr is not finding the text. I like to use MsgBox to see what an actual value of a variable is if something is not working right. In your case, I would put a MsgBox(0,"string",$string) right after $string=StringInStr($source,"schnitzel.png") and if it still pops up 0 even when the image exists I would then add MsgBox(0,"source",$source) So I could see what text it's getting. 010101000110100001101001011100110010000001101001011100110010000 001101101011110010010000001110011011010010110011100100001 My Android cat and mouse gamehttps://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek We're gonna need another Timmy! 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