AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Not working:Visit Weblink > Paste Text> Save >Close

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
RIKI



Joined: 14 May 2008
Posts: 1

PostPosted: Wed May 14, 2008 8:36 pm    Post subject: Not working:Visit Weblink > Paste Text> Save >Close Reply with quote

Can someone PLEASE hold my hand here? I after hours of troubleshooting, I have exhausted my patience with a very simple task.

Yes, I am a new user of AHK (but before writing to you all, I made sure to study the program & help menu). Still, I am going crazy here.

Mind you, so far, I thought to just use the Autoscript recorder (because it looked like a no brainer, saving me from learning how to write code).

I would appreciate direction on how to achieve my goal (and perhaps even wrote the code for me so I can understand where I am going wrong).

This is what I want to do (very simple):

• Visit https://post.craigslist.org/sdo/S/msg/csd to add text into a body.
• Copying prewritten text into my clipboard.
• Paste the clipboard contents into that web link’s empty body.
• Click on the web link’s CONTINUE button (to finish task).

A few things go haywire:

• The Autoscript recorder does not seem to copy my text into the clipboard & past it into mentioned web link body. The only way for me to get text into that body is to type it in real time.

• Autoscript recorder seems to move too fast & does not pick up every prompt I do. The result is an unfinished Macro. Also, the text that was force to type in real time ends up getting pasted wrong areas of my the web link (like the TITLE fields instead of the BODY field.

• Sometimes, when I finish an AHK file (even if it is wrong) will not appear to execute (at least not visually on the desktop) unless links & files that I used for it are OPEN on the desktop.

Ultimately, I know it would be wisest to write code (instead of use Autoscript recorder). I sure would appreciate someone would write my first task here (and I will learn from it). I bet many other readers would value your help here too (because my task might be a very common one). Thanks.
Back to top
View user's profile Send private message
BoBo²
Guest





PostPosted: Wed May 14, 2008 9:12 pm    Post subject: Reply with quote

It'll be less difficult to understand your attempt if you'd provide your code.
Don't be afraid, my coding is the worst on this planet, so yours won't be definitely that bad. Wink
Back to top
sinkfaze



Joined: 19 Mar 2008
Posts: 138

PostPosted: Thu May 15, 2008 12:18 am    Post subject: Reply with quote

BoBo² wrote:
It'll be less difficult to understand your attempt if you'd provide your code.


Also, tell us which web browser you're using if your code doesn't clearly indicate it.
_________________
Have trouble searching the site for information? Try Quick Search for Autohotkey.
Back to top
View user's profile Send private message
Hasso



Joined: 23 Mar 2005
Posts: 132
Location: Germany

PostPosted: Thu May 15, 2008 12:03 pm    Post subject: Reply with quote

And please inspect your keyboard. The Shift key seems to be stuck.

[ Moderator!: subject changed to proper case ]
_________________
Hasso

Programmers don't die, they GOSUB without RETURN
Back to top
View user's profile Send private message
tank



Joined: 21 Dec 2007
Posts: 471

PostPosted: Thu May 15, 2008 8:50 pm    Post subject: Reply with quote

for the function see
http://www.autohotkey.com/forum/viewtopic.php?t=30599
Code:

insert_text=
(
var x=document.forms(0).elements // collection of all the form elements for the first 0 based index form on the page
x(6).value='test' // this was the text area

x(24).click(); // this is the contnue button
)
IE7_InjectJS("san diego craigslist", insert_text)


so your askin how did i get the index valu for the elements collection

Code:

list_elements=
(
var x=document.forms;
win=window.open("blank.htm","forms1");

for (var f=0;f<=x.length-1;f++)  {
 win.document.writeln("<table border=1 cellspacing=0>");
win.document.writeln("<tr><td>form");
  win.document.writeln("</td><td>name");
  win.document.writeln("</td><td>id");
  win.document.writeln("</td><td>action");
win.document.writeln("</td><td>OnSubmit");
 win.document.writeln("<tr><td>");
  win.document.writeln("<tr><td>" + f);
  win.document.writeln("</td><td>&nbsp;");
  win.document.writeln(x[f].name);
  win.document.writeln("</td><td>&nbsp;");
  win.document.writeln(x[f].id);
  win.document.writeln("</td><td>&nbsp;");
  win.document.writeln(x[f].action);
  win.document.writeln("</td><td>&nbsp;");
  win.document.writeln(x[f].OnSubmit);
  win.document.writeln("</td></tr>");

 win.document.writeln("</table>");

 win.document.writeln("<table border=1 cellspacing=0>");
win.document.writeln("<tr><td>Element");
  win.document.writeln("</td><td>name");
  win.document.writeln("</td><td>id");
  win.document.writeln("</td><td>value");
win.document.writeln("</td><td>type");
win.document.writeln("</td><td>onclick");
win.document.writeln("</td><td>onchange");
win.document.writeln("</td><td>innerHTML");
  win.document.writeln("</td></tr>");
var l=x[f].elements
for (var i=0;i<=l.length-1;i++) 
{
win.document.writeln("<tr><td>" + i);
win.document.writeln("</td><td>"+l[i].name);
win.document.writeln("</td><td>"+l[i].id);
win.document.writeln("</td><td>"+l[i].value);
win.document.writeln("</td><td>"+l[i].type);
win.document.writeln("</td><td>"+l[i].onClick);
win.document.writeln("</td><td>"+l[i].onChange);
win.document.writeln("</td><td>"+l[i].innerHTML);
win.document.writeln("</td></tr>");
 }

 win.document.writeln("</table>");
  }


 win.document.writeln("</table>");
 win.document.writeln("<table border=1 cellspacing=0>");
win.document.writeln("<tr><td>All links index");
  win.document.writeln("</td><td>href");
  win.document.writeln("</td><td>target");
  win.document.writeln("</td><td>innerHTML");
  win.document.writeln("</td><td>name");
  win.document.writeln("</td><td>id");
  win.document.writeln("</td><td>class");
  win.document.writeln("</td><td>onclick");
  win.document.writeln("</td></tr>");
var y=document.links;
for (var m=0;m<=y.length-1;m++)  {
  win.document.writeln("<tr><td>" + m);
  win.document.writeln("</td><td>&nbsp;");
  win.document.writeln(y[m].href);
  win.document.writeln("</td><td>&nbsp;");
  win.document.writeln(y[m].target);
  win.document.writeln("</td><td>&nbsp;");
  win.document.writeln(y[m].innerHTML);
  win.document.writeln("</td><td>&nbsp;");
  win.document.writeln(y[m].name);
  win.document.writeln("</td><td>&nbsp;");
  win.document.writeln(y[m].id);
  win.document.writeln("</td><td>&nbsp;");
  win.document.writeln(y[m].className);
  win.document.writeln("</td><td>&nbsp;");
  win.document.writeln(y[m].onclick);
  win.document.writeln("</td></tr>");
}
 win.document.writeln("</table>");
)
IE7_InjectJS("san diego craigslist", list_elements)


now do me a favor
next time you see a post on how to fill out a web form point that person here
more information on use of Dom and javascript can be found here
http://www.w3schools.com
_________________
Read this
Com
Automate IE7 with Tabs
Back to top
View user's profile Send private message
CannedCheese



Joined: 22 May 2008
Posts: 39

PostPosted: Thu Jun 12, 2008 3:40 am    Post subject: Reply with quote


Does this still work? I've clicked the link and bound the two examples to F2 and F3, respectively [edit: list all elements works-- was blocked by the IE popup blocker, but the script to fill out the form on craigslist still does not work for me]. I'm able to use IE7_Nav and the other examples in Tank's Automation Example no problem. I do have #Include COM.AHK with the file in my script directory. Nothing happens. I'm a javascript noob. Can I manually paste a line in my browser to test if it should work?

I should add-- windows explorer is closed (if this matters).

Ultimately, I would like to navigate to a website automatically, fill in a form (like I think this example does), click the submit button, and then run something like

Code:

javascript:var o=document.documentElement.innerHTML;window.clipboardData.setData("Text",o);void(0);


to retrieve the results to the clipboard and then parse them in AHK where I am more comfortable.
Back to top
View user's profile Send private message
tank



Joined: 21 Dec 2007
Posts: 471

PostPosted: Thu Jun 12, 2008 5:06 am    Post subject: Reply with quote

glad to here things worked
Now lets talk about whats wrong
first the com library shouldnt be an include it should be placed in a folder called lib in the autohotkey directory
example:
c:\program files\autohotkey\lib

then you will not need the include directive
so then you want to fill out the form here
https://post.craigslist.org/sdo/S/msg/csd
sounds like you got the list elements js working but are missing something
lets have a look at the list elements again then see if you can follow this

Code:
Run, https://post.craigslist.org/sdo/S/msg/csd
WinWait,san diego craigslist,
COM_Init()
IE7_readyState(IE7_Get("san diego craigslist"))

IE7_ExecuteJS(IE7_Get("san diego craigslist"), "document.forms(0).elements(3).value='posting title';")
IE7_ExecuteJS(IE7_Get("san diego craigslist"), "document.forms(0).elements(4).value='1.00';")
IE7_ExecuteJS(IE7_Get("san diego craigslist"), "document.forms(0).elements(5).value='france';")
IE7_ExecuteJS(IE7_Get("san diego craigslist"), "document.forms(0).elements(6).value='this is my description';")
IE7_ExecuteJS(IE7_Get("san diego craigslist"), "document.forms(0).elements(8).value='clanpdf@insightbb.com';")
IE7_ExecuteJS(IE7_Get("san diego craigslist"), "document.forms(0).elements(9).value='clanpdf@insightbb.com';")
IE7_Button_click(IE7_Get("san diego craigslist"),"Add / Edit Images ")
COM_Term()

Im hoping your having a duh moment right now but if not might need to studdy dom again a but more at w3schools.com
_________________
Read this
Com
Automate IE7 with Tabs
Back to top
View user's profile Send private message
CannedCheese



Joined: 22 May 2008
Posts: 39

PostPosted: Thu Jun 12, 2008 8:08 am    Post subject: Reply with quote

Quote:
c:\program files\autohotkey\lib

Ok, I got the lib thing once I moved COM.ahk and renamed my IEFunctions.ahk file to IE7.ahk. Had to read the help file a few times before I realized that one must use the prefix of the function (before the underscore) for it to be included. Thanks for the tip.

I bound your GetElements function in your IE7_Tab post to F6, and couldn't get it to work until I realized that I was attempting to execute it on a tab, and the built-in IE7 popup blocker was blocking it, on a different tab (the first one). Hopefully others that are having problems will look for this.

I had to modify your code a little bit to get it to work for me. I think IE7_readyState is supposed to wait for the page to finish loading, but it doesn't for whatever reason...
Code:

Run, iexplore.exe https://post.craigslist.org/sdo/S/msg/csd
WinWait,san diego craigslist,
COM_Init()
sleep, 1000
IE7_readyState(IE7_Get("san diego craigslist"))

IE7_ExecuteJS(IE7_Get("san diego craigslist"), "document.forms(0).elements(3).value='posting title';")
IE7_ExecuteJS(IE7_Get("san diego craigslist"), "document.forms(0).elements(4).value='1.00';")
IE7_ExecuteJS(IE7_Get("san diego craigslist"), "document.forms(0).elements(5).value='france';")
IE7_ExecuteJS(IE7_Get("san diego craigslist"), "document.forms(0).elements(6).value='this is my description';")
IE7_ExecuteJS(IE7_Get("san diego craigslist"), "document.forms(0).elements(8).value='clanpdf@insightbb.com';")
IE7_ExecuteJS(IE7_Get("san diego craigslist"), "document.forms(0).elements(9).value='clanpdf@insightbb.com';")
IE7_Button_click(IE7_Get("san diego craigslist"),"Add / Edit Images "); THIS LINE DOES NOT CLICK THE BUTTON FOR ME
COM_Term()


With the sleep function added, the entire form is filled out, except the button is never clicked.
Quote:

Im hoping your having a duh moment right now but if not might need to studdy dom again a but more at w3schools.com

I'll be honest. I found that page on my own 2 days ago googling javascript and DOM, and I've just started going thru their HTML tutorial. I'm hoping I can use your example as a way to cleanly fill out a single form box, click a button, and then write the
Code:

javascript:var o=document.documentElement.innerHTML;window.clipboardData.setData("Text",o);void(0);

code to the addressbar in the background (I don't even know how to write to an address bar without activating the window) so that I can handle the data in ahk.

I certainly plan to learn javascript, dom, html (obv), and understand COM, but
1) I've taken off a month and a half from my 2nd job to write AHK script and I'm running out of time and money, and
2) I work much better by taking working programs apart and dissecting them. I think in the long run retrieving the data I need outside of ahk and then passing just the needed items into ahk variables seems much cleaner than copying the entire contents to the clipboard and then parsing it (may not be, I'm clueless here).

To illustrate that last parenthetical, shouldn't
Code:

f5::
msgbox % IE7_InjectJS("autohotkey", "var x=document.body.innerHTML;","x")
return


do something when I've navagated to www.autohotkey.com?

I get a blank msgbox.

[Edit] Somehow in all that fluff I forgot to thank you for your help and your routines. Thanks for both. I'm awed by how little I know and how much can be accomplished with AHK.
Back to top
View user's profile Send private message
tank



Joined: 21 Dec 2007
Posts: 471

PostPosted: Thu Jun 12, 2008 12:54 pm    Post subject: Reply with quote

the thanks comes in the effort
the problem of the not clicking is mine
some machines are faster than others i suppose might be why the readystate in the initial part of the code isnt working
you did what i would have there
but clicking that button onlyfor me only worked like this

Code:
IE7_ExecuteJS(IE7_Get("san diego craigslist"), "document.forms(0).elements(13).click();")


Now i didnt actually test this button push for this form and at worst there was a space at the end and the / wasnt escaped but in re peaking at the list elements i realised im having you clikc the wrong button
Code:
IE7_Button_click(IE7_Get("san diego craigslist"),"continue")

I tested this
_________________
Read this
Com
Automate IE7 with Tabs
Back to top
View user's profile Send private message
CannedCheese



Joined: 22 May 2008
Posts: 39

PostPosted: Thu Jun 12, 2008 9:14 pm    Post subject: Reply with quote

Thanks Tank. It works great and with your new code I can get it to click both buttons. I’ve tweaked it a tiny bit and have gotten it to work on other pages as well. It really makes it easier (for me) to learn from taking apart a working example. Now, I hope you won’t mind two more questions:

1) You state that you would use a sleep command as well. I was hoping that there would be a way, through the IE7_readyState (which returns 0 long before the page I need to load has loaded), to check that the page/tab has finished loading in the background (the pages that I need to hit vary greatly depending on traffic, it seems, and can take anywhere from 1 to 15 seconds to load). I tried setting up a loop that checks IE7_readyState but a 0 is returned long before the page has finished loading. I use firefox for my browser but actually like the idea of using IE7 for all automation, since a) it seems easier to automate and b) it allows me not to get confused as to which instance in currently running a script-- I can leave it alone when automating a task. In firefox, I’ve had to resort to all kinds of imagesearch and pixelsearch routines to ensure that a page has finished loading. A foolproof way to determine if an IE page has loaded (when minimized or in the background) would be sweet. I know there may be other methods though I'm not sure that they apply to inactive windows (or tabs). Should I be looking into something other than the IE7_readyState function for this?

2) In this craigslist example, can I now use IE7_Nav or IE7_ExecuteJS to write the javascript code to the current "san diego craigslist" tab in the background that copies the entire resulting html to the clipboard?
Code:
 javascript:var o=document.documentElement.innerHTML;window.clipboardData.setData("Text",o);void(0);

Through your other example, I’m able to use IE7_Nav is to change the chosen tab to a new url, but (and even if it is possible I may need to change the formatting of the above line of code to handle special characters correctly) could I use it to write javascript to a minimized address bar (or use some type of command similar to a controlsend)? Or is this something that I can do with utilize IE7_ExecuteJS?

Or is it possible to send info to a control like in the other thread (I don’t understand the following code and will need to learn COM)?

Code:

IETabWindow(pwb)
{
   psb  :=   COM_QueryService(pwb,IID_IShellBrowser:="{000214E2-0000-0000-C000-000000000046}")
   DllCall(NumGet(NumGet(1*psb)+12), "Uint", psb, "UintP", hwndTab)
   DllCall(NumGet(NumGet(1*psb)+ 8), "Uint", psb)
   Return   hwndTab
}


Thanks for helping a noob. I’m starting thru the javascript tutorials on the w3 site and I’m impressed (though I should probably learn html first).
Back to top
View user's profile Send private message
tank



Joined: 21 Dec 2007
Posts: 471

PostPosted: Thu Jun 12, 2008 11:09 pm    Post subject: Reply with quote

CannedCheese wrote:
Thanks Tank. It works great and with your new code I can get it to click both buttons. I’ve tweaked it a tiny bit and have gotten it to work on other pages as well. It really makes it easier (for me) to learn from taking apart a working example. Now, I hope you won’t mind two more questions:

1) You state that you would use a sleep command as well. I was hoping that there would be a way, through the IE7_readyState (which returns 0 long before the page I need to load has loaded), to check that the page/tab has finished loading in the background (the pages that I need to hit vary greatly depending on traffic, it seems, and can take anywhere from 1 to 15 seconds to load). I tried setting up a loop that checks IE7_readyState but a 0 is returned long before the page has finished loading. I use firefox for my browser but actually like the idea of using IE7 for all automation, since a) it seems easier to automate and b) it allows me not to get confused as to which instance in currently running a script-- I can leave it alone when automating a task. In firefox, I’ve had to resort to all kinds of imagesearch and pixelsearch routines to ensure that a page has finished loading. A foolproof way to determine if an IE page has loaded (when minimized or in the background) would be sweet. I know there may be other methods though I'm not sure that they apply to inactive windows (or tabs). Should I be looking into something other than the IE7_readyState function for this?

2) In this craigslist example, can I now use IE7_Nav or IE7_ExecuteJS to write the javascript code to the current "san diego craigslist" tab in the background that copies the entire resulting html to the clipboard?
Code:
 javascript:var o=document.documentElement.innerHTML;window.clipboardData.setData("Text",o);void(0);

Through your other example, I’m able to use IE7_Nav is to change the chosen tab to a new url, but (and even if it is possible I may need to change the formatting of the above line of code to handle special characters correctly) could I use it to write javascript to a minimized address bar (or use some type of command similar to a controlsend)? Or is this something that I can do with utilize IE7_ExecuteJS?

Or is it possible to send info to a control like in the other thread (I don’t understand the following code and will need to learn COM)?

Code:

IETabWindow(pwb)
{
   psb  :=   COM_QueryService(pwb,IID_IShellBrowser:="{000214E2-0000-0000-C000-000000000046}")
   DllCall(NumGet(NumGet(1*psb)+12), "Uint", psb, "UintP", hwndTab)
   DllCall(NumGet(NumGet(1*psb)+ 8), "Uint", psb)
   Return   hwndTab
}


Thanks for helping a noob. I’m starting thru the javascript tutorials on the w3 site and I’m impressed (though I should probably learn html first).



OK first things first
after the page loads initially the readystate function will work fine
there are other longer ways to do that but i never bothered to write a function for it


next
Why the clipboard
i spose you could just
Code:
clipboard:=IE7_Get_Dom(this_page,0)

that would load the entirety of the html to the clip board but i cant imagin a good reason for it
lets look breifly at what i just did
this_page is a pointer variable arrived at in such a method as this
Code:
this_page:=IE7_get("san diego craigslist")

i can use this variable now instead of
Code:
IE7_get("san diego craigslist")

that i used in my example and its better practice
the IE7_Get_Dom uses this pointer and gets a named or index from the document.all collection 0 is the first element of a page
it will return the entire contents of the html element
using the clipboard:= tells the function to just load the return value directly to the clipboard


There isnt a good reason at this stage for you to bother with
Code:

IETabWindow(pwb)
{
   psb  :=   COM_QueryService(pwb,IID_IShellBrowser:="{000214E2-0000-0000-C000-000000000046}")
   DllCall(NumGet(NumGet(1*psb)+12), "Uint", psb, "UintP", hwndTab)
   DllCall(NumGet(NumGet(1*psb)+ 8), "Uint", psb)
   Return   hwndTab
}


Seans post was more academic than something needed for the scripts
i wont pretend to be an expert on it but suffice it to say it isnt needed for automating DOM script in IE but you might use it if changing the browser settings



CannedCheese wrote:
Through your other example, I’m able to use IE7_Nav is to change the chosen tab to a new url, but (and even if it is possible I may need to change the formatting of the above line of code to handle special characters correctly) could I use it to write javascript to a minimized address bar (or use some type of command similar to a controlsend)? Or is this something that I can do with utilize IE7_ExecuteJS?

yes you could send the js to minimised address bar that way
yes u could use in injectjs
Code:

my_js=
(
var o=document.documentElement.innerHTML;window.clipboardData.setData("Text",o);void(0);
)
IE7_ExecuteJS(IE7_Get("san diego craigslist"), my_js)

notice i took out javascript: in the inject js

Thats all for now on the way out hope it helps ill follow up if you have more questions
_________________
Read this
Com
Automate IE7 with Tabs
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group