UBotBuddy 331 Posted May 14, 2010 Report Share Posted May 14, 2010 Are there any examples whereby I can run some javascript code and place the output into a Sey variable within UBot? I would love to see this if someone has done this. I tried using $eval but no luck. Thanks! Quote Link to post Share on other sites
Net66 54 Posted May 14, 2010 Report Share Posted May 14, 2010 Hi Buddy, Here is a sample from one of my bots that does date manipulation and puts the output into a variable. Is that what you meant? Andy 1 Quote Link to post Share on other sites
UBotBuddy 331 Posted May 15, 2010 Author Report Share Posted May 15, 2010 Hey Andy, How do you get it to execute the script? This was the first one that I tried but the only output is the source code itself. Buddy Quote Link to post Share on other sites
Net66 54 Posted May 15, 2010 Report Share Posted May 15, 2010 Hey Andy, How do you get it to execute the script? This was the first one that I tried but the only output is the source code itself. Buddy That is odd. That screen shot is exactly how I have it and it works fine here. Can anyone else confirm if this works for them or not? Buddy - if you want to knock up a bot that does this and email it to me I will load it into ubot here and see if it works just to eliminate the possibility of it being a local issue. andy [at] netodex.com Andy Quote Link to post Share on other sites
UBotBuddy 331 Posted May 15, 2010 Author Report Share Posted May 15, 2010 Hey Andy! As soon as I get back to my office this evening I will shoot something to you. Buddy Quote Link to post Share on other sites
UBotBuddy 331 Posted May 15, 2010 Author Report Share Posted May 15, 2010 Email sent. Quote Link to post Share on other sites
Net66 54 Posted May 15, 2010 Report Share Posted May 15, 2010 Email sent. OK this is bizarre. It didn't work for me so I tried copying and pasting a javascript function from an existing bot into the bot you sent and it worked but the two functions look identical. So I saved that bot under a new name, loaded up your original and copied the javascript part into the bot I just saved so it now had my code and the one you sent and both worked! So.. I reloaded the bot you sent. Ran it, it did not work. Copied in my version of the same java evaluate and set a new ui monitor as mine was the same but with a diff variable name. Ran it and only my variable showed correct. I hit refresh and ran it again and BOTH worked. There is something very screwy going on with the eval and javascript here but I cannot figure out what. See this for yourself. Attached are two bots. One called 'working' and one called 'notworking'. Try them both and see the difference. Now go to the working one and copy the node with the evaluation in it. Paste it into the non working bot under the existing set/eval node. Add a ui monitor for #StartDate and run the bot. Only the new set command works. Now hit refresh and run it again - Both work! working.ubotnotworking.ubot A very odd bug. Andy Quote Link to post Share on other sites
UBotBuddy 331 Posted May 16, 2010 Author Report Share Posted May 16, 2010 Well! At least I'm not going crazy. I was beginning to think I was doing something wrong. Buddy Quote Link to post Share on other sites
alcr 135 Posted May 16, 2010 Report Share Posted May 16, 2010 I notified Seth about this And very good job pinpointing the bug! Quote Link to post Share on other sites
Net66 54 Posted May 16, 2010 Report Share Posted May 16, 2010 I notified Seth about this And very good job pinpointing the bug! Can't help but try to pinpoint... its the old school programmer in me lol. Quote Link to post Share on other sites
Seth Turin 223 Posted May 17, 2010 Report Share Posted May 17, 2010 you guys should have a good lol over this one. this was starting to drive me nuts too, as I reproduced your results but I couldn't explain it. then I copied the contents of the eval statements into a text editor. working:var d = new Date("05/16/2010 21:25:20"); d.setDate(d.getDate()); var curr_date = d.getDate(); var curr_month = d.getMonth(); curr_month++; var curr_year = d.getFullYear(); curr_month + "/" + curr_date + "/" + curr_year; not working:var d = new Date("05/16/2010 21:40:25"); d.setDate(d.getDate()); var curr_date = d.getDate(); var curr_month = d.getMonth(); curr_month++; var_curr_year = d.getFullYear(); curr_month + "/" + curr_date + "/" + curr_year; do you see it yet? if you look at the 3rd line from the bottom, one says var curr_year = d.getFullYear(); while the other says var_curr_year = d.getFullYear(); that added underscore in the not working one fail to set the proper variable. but here's where the real madness comes in. the reason it worked when you had both is because when it runs the working one, the proper variable gets set and stored in that instance of internet explorer, so when it recalls it in the not working version, the variable is remembered from the first one. long story short, the error is in the javascript, but you were justified in your pulling your hair out Quote Link to post Share on other sites
UBotBuddy 331 Posted May 17, 2010 Author Report Share Posted May 17, 2010 WELL! As I wipe the Egg off my face I will extend a THANK YOU to Seth and an apology to Andy! I screwed up Andy's script. As a result I do have a question. Will we have the ability at some point to paste in Javascripts from like notepad into a UBot object like this one? Again Thanks Seth and Andy! Quote Link to post Share on other sites
Net66 54 Posted May 17, 2010 Report Share Posted May 17, 2010 you guys should have a good lol over this one. this was starting to drive me nuts too, as I reproduced your results but I couldn't explain it. then I copied the contents of the eval statements into a text editor. working:var d = new Date("05/16/2010 21:25:20"); d.setDate(d.getDate()); var curr_date = d.getDate(); var curr_month = d.getMonth(); curr_month++; var curr_year = d.getFullYear(); curr_month + "/" + curr_date + "/" + curr_year; not working:var d = new Date("05/16/2010 21:40:25"); d.setDate(d.getDate()); var curr_date = d.getDate(); var curr_month = d.getMonth(); curr_month++; var_curr_year = d.getFullYear(); curr_month + "/" + curr_date + "/" + curr_year; do you see it yet? if you look at the 3rd line from the bottom, one says var curr_year = d.getFullYear(); while the other says var_curr_year = d.getFullYear(); that added underscore in the not working one fail to set the proper variable. but here's where the real madness comes in. the reason it worked when you had both is because when it runs the working one, the proper variable gets set and stored in that instance of internet explorer, so when it recalls it in the not working version, the variable is remembered from the first one. long story short, the error is in the javascript, but you were justified in your pulling your hair out Doh! And I sat and compared those two java scripts at least a dozen times and didn't spot it! Thanks Seth. Andy Quote Link to post Share on other sites
MAtkins 0 Posted July 1, 2010 Report Share Posted July 1, 2010 In coding generally, if his works and yours doesn't, you've got a typo:) Quote Link to post Share on other sites
MAtkins 0 Posted July 2, 2010 Report Share Posted July 2, 2010 I've got a problem though: I added a 'set' and made the value an $eval with the expression:sForms = ""; for(i=0;i<document.forms.length;i++){ sForms += document.forms.outerHTML + "||"}; sForms += ""; This of course is javascript and I've created a string variable that has all the outer html for every form on the page, delimited by "||". I end the javascript with sForms += ""; just to make sure the return value is the var sForms. It works fine if there's only one form on the page.It doesn't work if there are more than 1.It returns nothing. I tried it using run javascript with my #sForms var (a UBots variable) set as a parameter.My last line in that script was "{1}" = sForms;That didn't work either. I'm trying to get a list %Forms that contains the outer html for each form on the page. Any ideas? Quote Link to post Share on other sites
MAtkins 0 Posted July 2, 2010 Report Share Posted July 2, 2010 Here's something strange. if the page in the browser has a script on it, the javascript functionality in UBots seems to work pretty well. BUT - if there is no javascript on the page UBots cannot process javascript at all.Also, if a javascript error occurs on a page, Ubots cannot process javascript. Is there a way to make it work even if there's no javascript on the page or if javascript throws an error? Solve this for me and I've got a really *sweet* bot I'll publish, free and soon. Quote Link to post Share on other sites
tooltrainer 12 Posted July 3, 2010 Report Share Posted July 3, 2010 Hoping one of you guys can clear something up for me. I've been needing to do exactly this - grab the result of a javascript and store it into a UBot variable. I had no idea JS would execute in any wau other than a "run javascript" node, so being able to "eval" it is very cool! But it's not working for me at all and I'm sure I must be doing something wrong. Here is what I've done: node 1 - set #start eval "var start = new Date().getTime();" node 2 - set #elapsed eval "var elapsed = (new Date().getTime() - {1}) / 60000;" {1} = #start node 3 - set #final_time eval "{1} - {2}" {1} = #elapsed {2} = #start node 4 - set #timer_msg alert('Total elapsed time: ' + Math.round({1}*100)/100 + ' minutes.'); {1} = #final_time node 5 - run javascript alert('{1}'); {1} = #timer_msg Hopefully this makes sense... am I even remotely on the right track here? Jonathan Quote Link to post Share on other sites
alcr 135 Posted July 3, 2010 Report Share Posted July 3, 2010 Here's something strange. if the page in the browser has a script on it, the javascript functionality in UBots seems to work pretty well. BUT - if there is no javascript on the page UBots cannot process javascript at all.Also, if a javascript error occurs on a page, Ubots cannot process javascript. Is there a way to make it work even if there's no javascript on the page or if javascript throws an error? Solve this for me and I've got a really *sweet* bot I'll publish, free and soon.This is because the Internet Explorer javascript engine does not load in if there aren't any javascript on the page. And as far as I know, nothing can be done about that right now. Quote Link to post Share on other sites
Frank 177 Posted September 14, 2010 Report Share Posted September 14, 2010 I know that this is an old thread, but damn, solved my problem! This one should be stickied. It clearly shows how to pass variables into and out of a slice of javascript. Frank Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.