 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Do you think this tutorial is beneficial to the AHK Community? |
| Yeah, I think this tutorial is a great value-add to the Community. |
|
86% |
[ 91 ] |
| Nope - I think this tutorial is a waste of web space. |
|
0% |
[ 1 ] |
| I think this tutorial would be better if it incorporated AHK_L & COM_L. |
|
12% |
[ 13 ] |
|
| Total Votes : 105 |
|
| Author |
Message |
sinkfaze
Joined: 18 Mar 2008 Posts: 5044 Location: the tunnel(?=light)
|
Posted: Wed Feb 03, 2010 5:32 pm Post subject: |
|
|
Have you navigated to the page yet?
| Code: | url:="http://www.thatwebsiteyourlywant2get2.com"
COM_Init()
pwb := COM_CreateObject("InternetExplorer.Application")
COM_Invoke(pwb , "Visible=", "True") ;"False" ;"True" ;
COM_Invoke(pwb, "Navigate",url)
Loop
if (COM_Invoke(pwb,"readyState") = 4) ; wait for page to load
break
text := COM_Invoke(pwb, "document.documentElement.outerHTML") ; should be correct to get the source
msgbox %text% |
_________________ Try Quick Search for Autohotkey or see the tutorial for newbies. |
|
| Back to top |
|
 |
randallf
Joined: 06 Jul 2009 Posts: 678
|
Posted: Wed Feb 03, 2010 5:37 pm Post subject: |
|
|
| sinkfaze wrote: | Have you navigated to the page yet?
| Code: | url:="http://www.thatwebsiteyourlywant2get2.com"
COM_Init()
pwb := COM_CreateObject("InternetExplorer.Application")
COM_Invoke(pwb , "Visible=", "True") ;"False" ;"True" ;
COM_Invoke(pwb, "Navigate",url)
Loop
if (COM_Invoke(pwb,"readyState") = 4) ; wait for page to load
break
text := COM_Invoke(pwb, "document.documentElement.outerHTML") ; should be correct to get the source
msgbox %text% |
|
This is awesome, and exactly the example I'm looking for (thank you!) but I still receive an error.
I am using AHK_L and the COM (not _L) standard library at the moment. I'm thinking this might be the problem.
Do I have to use the latest official AHK with this?
Can I use AHK_L and the COM_L library? |
|
| Back to top |
|
 |
jethrow
Joined: 24 May 2009 Posts: 1907 Location: Iowa, USA
|
Posted: Wed Feb 03, 2010 6:42 pm Post subject: |
|
|
| randallf wrote: | | I am using AHK_L and the COM (not _L) standard library at the moment. | Don't do that
| randallf wrote: | | Can I use AHK_L and the COM_L library? | Try this: | Code: | url:="http://www.thatwebsiteyourlywant2get2.com"
pwb := COM_CreateObject("InternetExplorer.Application")
pwb.Visible := True
pwb.Navigate(url)
Loop
if (pwb.readyState = 4) ; wait for page to load
break
text := pwb.document.documentElement.outerHTML ; should be correct to get the source
msgbox %text% |
_________________
- in case I forgot to smile
Basic Webpage Controls
COM Object Reference |
|
| Back to top |
|
 |
Gundeck
Joined: 26 Jan 2010 Posts: 5
|
Posted: Thu Feb 04, 2010 3:43 pm Post subject: Re: Basic Webpage Controls with JavaScript / COM - Tutorial |
|
|
[*]Dropdown Box Selection - selectedIndex | Quote: | | <SELECT class=post name=sort_by><OPTION selected value=0>Post Time</OPTION><OPTION value=1>Post Subject</OPTION><OPTION value=2>Topic Title</OPTION><OPTION value=3>Author</OPTION><OPTION value=4>Forum</OPTION></SELECT> | This is the HTML for the Sort By Dropdown. The following will set the Dropdown to Author: | Code: | javascript: document.all.sort_by.selectedIndex = 3; void 0 ; Note - you could use value = 3
COM_Invoke(pwb, "document.all.sort_by.selectedIndex", 3) |
I'm having troube getting the example to work with a drop down.
When I use IE HTML Element SPY I get a code of:
<SELECT style="WIDTH: 100px" id=selectedStatus onchange=javascript:changeMailingStatus(this.value,20); name=test> <OPTION selected value=0>Select Status</OPTION> <OPTION value=5>Archive</OPTION></SELECT>
There are multiple drop dows on the page. The next one would be:
<SELECT style="WIDTH: 100px" id=selectedStatus onchange=javascript:changeMailingStatus(this.value,21); name=test> <OPTION selected value=0>Select Status</OPTION> <OPTION value=5>Archive</OPTION></SELECT>
Any insight on how I would get AHK to make the appropriate selection to 5>Archive?
Thank You for the support. |
|
| Back to top |
|
 |
jethrow
Joined: 24 May 2009 Posts: 1907 Location: Iowa, USA
|
Posted: Thu Feb 04, 2010 4:48 pm Post subject: |
|
|
It should just be:
| Code: | javascript: document.all.selectedStatus.selectedIndex = 5; void 0 ; Note - you could use value = 5
COM_Invoke(pwb, "document.all.selectedStatus.selectedIndex", 5) |
Now, this drop down also has an "onchange" event | Quote: | | :<SELECT style="WIDTH: 100px" id=selectedStatus onchange=javascript:changeMailingStatus(this.value,20); name=test> <OPTION selected value=0>Select Status</OPTION> <OPTION value=5>Archive</OPTION></SELECT> | You should be able to invoke this using the fireEvent method: | Code: | javascript: document.all.selectedStatus.selectedIndex.fireEvent('onchange')
COM_Invoke(pwb, "document.all.selectedStatus.selectedIndex.fireEvent", "onchange") | NOTE - untested _________________
- in case I forgot to smile
Basic Webpage Controls
COM Object Reference |
|
| Back to top |
|
 |
Gundeck
Joined: 26 Jan 2010 Posts: 5
|
Posted: Thu Feb 04, 2010 10:09 pm Post subject: |
|
|
| jethrow wrote: | It should just be:
| Code: | javascript: document.all.selectedStatus.selectedIndex = 5; void 0 ; Note - you could use value = 5
COM_Invoke(pwb, "document.all.selectedStatus.selectedIndex", 5) |
Now, this drop down also has an "onchange" event | Quote: | | :<SELECT style="WIDTH: 100px" id=selectedStatus onchange=javascript:changeMailingStatus(this.value,20); name=test> <OPTION selected value=0>Select Status</OPTION> <OPTION value=5>Archive</OPTION></SELECT> | You should be able to invoke this using the fireEvent method: | Code: | javascript: document.all.selectedStatus.selectedIndex.fireEvent('onchange')
COM_Invoke(pwb, "document.all.selectedStatus.selectedIndex.fireEvent", "onchange") | NOTE - untested |
How do I diferentiate bewteen the different dropdowns?
There are multiple per page, the only thing I can see that could possably be an identifier is "(this.value,20)" which inciments +1 for the next dropdown available.
I assume I somehow need to include that into the scripting? |
|
| Back to top |
|
 |
jethrow
Joined: 24 May 2009 Posts: 1907 Location: Iowa, USA
|
Posted: Thu Feb 04, 2010 11:33 pm Post subject: |
|
|
| Gundeck wrote: | | How do I diferentiate bewteen the different dropdowns? | By "dropdowns", I'm assuming you mean different dropdown boxes, and not the different options in the dropdown. Each dropdown should have a unique id | Quote: | | <SELECT style="WIDTH: 100px" id=selectedStatus onchange=javascript:changeMailingStatus(this.value,20); name=test> <OPTION selected value=0>Select Status</OPTION> <OPTION value=5>Archive</OPTION></SELECT> |
You're examples don't seem to follow this, which I haven't seen before. You could also get a collection of all the SELECT (dropdown) elements on the page: | Code: | javascript: select=document.all.tags('SELECT'); alert('There are ' + select.length + ' dropdowns on the page.')
select := COM_Invoke(pwb, "document.all.tags", "SELECT")
MsgBox, % "There are " COM_Invoke(select, "length") " dropdowns on the page." | *Remember, the variable "select" will now be an object, and needs to be released
You could now access the dropdown by which item it is in the collection (collection starts at 0):
| Code: | select[0]
COM_Invoke(select, "item", 0) |
_________________
- in case I forgot to smile
Basic Webpage Controls
COM Object Reference |
|
| Back to top |
|
 |
Guest
|
Posted: Mon Feb 08, 2010 4:06 pm Post subject: |
|
|
| jethrow wrote: | | randallf wrote: | | I am using AHK_L and the COM (not _L) standard library at the moment. | Don't do that
| randallf wrote: | | Can I use AHK_L and the COM_L library? | Try this: | Code: | url:="http://www.thatwebsiteyourlywant2get2.com"
pwb := COM_CreateObject("InternetExplorer.Application")
pwb.Visible := True
pwb.Navigate(url)
Loop
if (pwb.readyState = 4) ; wait for page to load
break
text := pwb.document.documentElement.outerHTML ; should be correct to get the source
msgbox %text% |
|
This is really cool, I finally got it working - I think I had the wrong version of COM_L, I guess 2 versions come in the one zip??? - anyway, this works really great but is there a way to make it do it in the background, without opening a window?
Thanks again!!!  |
|
| Back to top |
|
 |
randallf
Joined: 06 Jul 2009 Posts: 678
|
Posted: Mon Feb 08, 2010 4:14 pm Post subject: |
|
|
| Quote: |
This is really cool, I finally got it working - I think I had the wrong version of COM_L, I guess 2 versions come in the one zip??? - anyway, this works really great but is there a way to make it do it in the background, without opening a window?
Thanks again!!!  |
I hardly deserve to call myself a programmer,
| Code: | | pwb.Visible := False |
when I miss stuff like this all the time.
TY!! |
|
| Back to top |
|
 |
jethrow
Joined: 24 May 2009 Posts: 1907 Location: Iowa, USA
|
Posted: Mon Feb 08, 2010 4:17 pm Post subject: |
|
|
| Code: | url:="http://www.thatwebsiteyourlywant2get2.com"
pwb := COM_CreateObject("InternetExplorer.Application")
pwb.Visible := True ; <--- leave this line out & the window will be Invisible ;)
pwb.Navigate(url)
Loop
if (pwb.readyState = 4)
break
text := pwb.document.documentElement.outerHTML
msgbox %text%
pwb.Quit() ; <--- this will close the Invisible IE window |
_________________
- in case I forgot to smile
Basic Webpage Controls
COM Object Reference |
|
| Back to top |
|
 |
Gundeck
Joined: 26 Jan 2010 Posts: 5
|
Posted: Tue Feb 09, 2010 10:11 pm Post subject: Why does this not work |
|
|
javascript: document.getElementsByTagName('input')[11].click()
COM_Invoke(pwb, "javascript: document.getElementsByTagName[input].item[11].click")
This is from the Tut.
What I'm trying to do is just a simple login into Facebook.
I got it entering in the User and Password using
COM_Invoke(userName:=COM_Invoke(all:=COM_Invoke(doc:=COM_Invoke(pwb,"Document"),"All"),"Item","Email"),"value",gUser)
COM_Invoke(password:=COM_Invoke(all,"Item","pass_placeholder"),"value",gPass)
from the COM tut, but I could not get this to work:
COM_Invoke(submit:=COM_Invoke(all,"Item","submit"),"click").
Mostly because the button does not have a name field os the other had. When I use various spy apps it comes up with:
,input value="Login" type="submit" class="UIButton_Text.
I can use:
javascript: document.getElementsByTagName('input')[6].click()
to fire it off, but it COM equivelent:
COM_Invoke(pwb, "javascript: document.getElementsByTagName[input].item[11].click")
Pops up errors.
I'm pretty nub in this whole thing, I have been following posts and have review almost every topic that involves "Facebook". I really don't want to send click or {TAB} {ENTER} to fire this button off. Am I missing something obvious?
Thanks all. |
|
| Back to top |
|
 |
sinkfaze
Joined: 18 Mar 2008 Posts: 5044 Location: the tunnel(?=light)
|
Posted: Tue Feb 09, 2010 10:23 pm Post subject: Re: Why does this not work |
|
|
| Gundeck wrote: | | Am I missing something obvious? |
Not entirely. Even though the input button does not have a name or ID, your information does show that it has a value:
| Code: | | input value="Login" type="submit" class="UIButton_Text. |
So what you need to do is look through input element collection, find the one with a value "Login" and click it:
| Code: | COM_Invoke(pwb,"document.all.item[email].value",gUser)
COM_Invoke(pwb,"document.all.item[pass_placeholder].value",gPass)
Loop % COM_Invoke(pwb,"document.all.tags[input].length") { ; loop runs equal to the number of input elements on the page
if (COM_Invoke(pwb,"document.all.tags[input].item[" A_Index-1 "].value") = "Login") { ; if current input element has value of 'Login'
COM_Invoke(pwb,"document.all.tags[input].item[" A_Index-1 "].click") ; click it
break ; break the loop
} ; else the loop continues
} |
_________________ Try Quick Search for Autohotkey or see the tutorial for newbies. |
|
| Back to top |
|
 |
jethrow
Joined: 24 May 2009 Posts: 1907 Location: Iowa, USA
|
Posted: Tue Feb 09, 2010 10:25 pm Post subject: |
|
|
| Quote: | | COM_Invoke(pwb, "javascript: document.getElementsByTagName[input].item[11].click") |
Thanks for pointing this out. Remove the red. I have updated the tutorial. _________________
- in case I forgot to smile
Basic Webpage Controls
COM Object Reference |
|
| Back to top |
|
 |
rhinox202
Joined: 23 Apr 2009 Posts: 34
|
Posted: Tue Feb 23, 2010 4:17 am Post subject: CSS !important |
|
|
Is there a way to add !important to the following code?
| Code: | | COM_Invoke(pwb, "document.getElementById[box].style.display", "none") |
I have tried adding " !important" after none, but that doesn't work. Doing so results in the following:
COM Error Notification
Function Name: "display"
ERROR: Not Implemented
(0x80004001)
ERROR2: The parameter is incorrect
(0x80070057)
I do not receive an error like this when adding !important to a margin style, so I am guessing that it may not be possible on the display style. If anyone can help I would appreciate it. Thanks. |
|
| Back to top |
|
 |
tank
Joined: 21 Dec 2007 Posts: 3700 Location: Louisville KY USA
|
Posted: Tue Feb 23, 2010 4:32 am Post subject: |
|
|
what on earth makes you think you should _________________
We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed; |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|