 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
BETLOG
Joined: 27 Nov 2006 Posts: 218 Location: Queensland, Australia
|
Posted: Tue Nov 28, 2006 8:25 am Post subject: controlsend (or equiv) on jscript web page help needed |
|
|
I am trying to ControlSend (or equivalent) to several text input fields on a .js web page (Primavera web interface).
I'm thinking that this is probably helpful, but cannot figure out how:
http://www.autohotkey.com/forum/viewtopic.php?t=14237
Here is some code snippets from one field on the page I want to put text into:
| Code: | <tr class="data_spacer"><td colspan=100></td></tr><tr>
<td class="label">Contact</td>
<td width=1%><img src="img/key_place_holder.gif"></td>
<td nowrap>
<table width=100% cellpadding=0 cellspacing=0 border=0>
<tr>
<td nowrap>
<input type="hidden" name="dailyReportMainCData.approvedVendor1Ini" value="KZL"> <span id="pf_approvedvendor1ini">
<input type="text" name="dailyReportMainCData.acceptedBy1" maxlength="22" value="Persons Name" onchange="setFormDirty();setApprovalGIF();" class="width_a"> </span>
<!-- enforces cell alignment - when null data -->
</td>
<td width=18% nowrap class=small>
<a href="javascript:void 0;" onclick="popupContactPicker('dailyReportMainCData.approvedVendor1');return false;">select...</a>
</td>
</tr>
</table>
</td>
</tr> |
It's the "Persons Name" field I'm interested in.
It's critical that I can send input to this field WITHOUT having the explorer window in focus.
I can get hold of the window Hwnd easy enough, but i am having trouble figuring how to put it in the right field.
Yes, this is a continuation of another thread; i'm hoping that by rewrding and simplifying I can get some help. |
|
| Back to top |
|
 |
BoBo Guest
|
Posted: Tue Nov 28, 2006 9:39 am Post subject: |
|
|
Use a bookmarklet and send it to the browser addressbar control (IE=Edit1).
| Code: | | ControlSend, Edit1, javascript:function EnterTextAtField() { with (document.forms[0]) { elements['name'].value = "Here we go!"; }}; void(EnterTextAtField()); {ENTER} |
|
|
| Back to top |
|
 |
BoBo Guest
|
Posted: Tue Nov 28, 2006 9:44 am Post subject: |
|
|
| Code: | | ControlSend, Edit1, javascript:function EnterTextAtField() { with (document.forms[0]) { elements['dailyReportMainCData.acceptedBy1'].value = "BETLOG"`; }}`; void(EnterTextAtField())`; {ENTER} | I guess you've to escape the semi-cola ! ... |
|
| Back to top |
|
 |
BETLOG
Joined: 27 Nov 2006 Posts: 218 Location: Queensland, Australia
|
Posted: Tue Nov 28, 2006 10:22 am Post subject: |
|
|
Hmmm, im confused.
I think ther eis something wrong with your syntax, but my limited knowledge isn't letting me see it.
ie:
I execute this with an .ahk:
| Code: | ControlSend, Edit1, javascript:function EnterTextAtField() { with (document.forms[0]) { elements['dailyReportMainCData.acceptedBy1'].value = "BETLOG"`; }}`; void(EnterTextAtField())`; {ENTER}, %ie%
|
and IE only receives this:
| Code: | | javascript:function EnterTextAtField() ; void(EnterTextAtField()); |
| Code: | and IE gives this js error:
Line: 1
Char: 29
Error: Expected '{'
code: 0
|
What doesn't it like about the parenthesies? |
|
| Back to top |
|
 |
BoBo Guest
|
Posted: Tue Nov 28, 2006 10:30 am Post subject: |
|
|
| Code: | ControlSend, Edit1, javascript:function EnterTextAtField() { with (document.forms[0]) { elements['dailyReportMainCData.acceptedBy1'].value = "BETLOG"`; }}`; void(EnterTextAtField())`;, %ie%
ControlSend, Edit1, {ENTER},%ie% |  |
|
| Back to top |
|
 |
BETLOG
Joined: 27 Nov 2006 Posts: 218 Location: Queensland, Australia
|
Posted: Tue Nov 28, 2006 10:44 am Post subject: |
|
|
No, it accepts the {enter} just fine at the end of the line, but i needed to escape the { and } with {{} and {}} in the code part..
...so now it feeds it into the IE address field ok, and 'enter's it ok... it just doesn't do anything after that.
It's obviously registering the {enter} though because i can see/hear it 'click' at the end of the input (which is relatively slow).
This is odd, because it looks like it should work, or give an error... and it's doing neither. |
|
| Back to top |
|
 |
BoBo Guest
|
Posted: Tue Nov 28, 2006 10:49 am Post subject: |
|
|
| Not escaping anything and use ControlSendRaw ? |
|
| Back to top |
|
 |
BoBo Guest
|
Posted: Tue Nov 28, 2006 11:00 am Post subject: |
|
|
| Quote: | If the target control is an Edit control (or something similar), the following are usually more reliable and faster than ControlSend:
Control, EditPaste, This text will be inserted at the caret position., ControlName, WinTitle
ControlSetText, ControlName, This text will entirely replace any current text., WinTitle | Might be of interest. |
|
| Back to top |
|
 |
BETLOG
Joined: 27 Nov 2006 Posts: 218 Location: Queensland, Australia
|
Posted: Tue Nov 28, 2006 11:19 am Post subject: |
|
|
Hmm, yes, that IS of interest...
But it's not the send mechanism thats failing; because the text/code gets to IE ok, it just has no effect when i/the script pushes enter.
Even if i strip out the raw js and paste it into the address bar, and hit enter, it does nothing.
Maybe my IE security default settings are wrong, but i just checked them and loosened a few restrictions with no effect
Thanks for the suggestions so far BoBo, it's been very helpful.... but i'm still stuck on why IE wont action it.
I can't imagine how it would differentiate between keyed entry and direct form manipulation, but i suppose it could. Primavera seems to be quite annoying with things like that... so maybe it's the application thats stopping it from working, not IE... because (as usual) AHK seems to be working just fine). |
|
| Back to top |
|
 |
PhiLho
Joined: 27 Dec 2005 Posts: 6721 Location: France (near Paris)
|
Posted: Tue Nov 28, 2006 5:35 pm Post subject: |
|
|
| BoBo wrote: | | I guess you've to escape the semi-cola ! ... | What is a semi-cola? Pepsi?
BETLOG, are you sure your input is in form[0]? This info isn't in the fragment you provided.
See Using one line JavaScript code to manipulate Web pages for some additional hints (the JS line given by BoBo is a bit convoluted...). _________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2") |
|
| Back to top |
|
 |
BoBo Guest
|
Posted: Tue Nov 28, 2006 5:50 pm Post subject: |
|
|
| Quote: | | (the JS line given by BoBo is a bit convoluted...). | Hey, its proudly stolen from the net  |
|
| Back to top |
|
 |
BETLOG
Joined: 27 Nov 2006 Posts: 218 Location: Queensland, Australia
|
Posted: Wed Nov 29, 2006 2:58 am Post subject: |
|
|
| PhiLho wrote: | | BoBo wrote: | | I guess you've to escape the semi-cola ! ... | What is a semi-cola? Pepsi? :-) |
Dr Pepper }:)
| Quote: | | BETLOG, are you sure your input is in form[0]? This info isn't in the fragment you provided. |
I have been using various modifications of what BoBo has suggested, as well as his suggestions verbatim...as I know suggestions usually contain errors/omissions that I need to remove/fix.
As everybody seems to say: it's a proprietry document covered in copyright notices, so i cant show too much of it, but suffice it to say it's a Primavera web interface html document.
Basically, the only form in the doc that I can find is:
| Code: | | <form name="dailyreportdetailform" method="Post" action="/exponline/dailyreportdetail.do"> | And because one of the topmost lines in the code refers to:
| Code: | | window.document.forms['dailyreportdetailform'].elements("dailyReportMainCData.dayOfWeek").focus(); | ...and I know that the field in focus when the page opens is in the same section of code, and same section in the page as the ones I want... i assume it's got to be either [0] or ['dailyreportdetailform'].
..right?
A little further down in the html is the input i'm after: | Code: |
<input type="hidden" name="dailyReportMainCData.approvedVendor1Ini" value="D9"> <span id="pf_approvedvendor1ini">
<input type="text" name="dailyReportMainCData.acceptedBy1" maxlength="22" value="BETLOG" onchange="setFormDirty();setApprovalGIF();" class="width_a"> |
The AHK to inject the js bookmarklet into IE works fine, it's just that nothing happens when it does so... no response, no error... not even if all i do is adjust and paste in a focus() from the pages own source.
eg:
| Code: | | javascript:window.document.forms['dailyreportdetailform'].elements("dailyReportMainCData.dayOfWeek").focus(); |
Which, although I don't show it here, is the first text field on the page, and is always bought to selected focus when the page loads.
This is the code I feel should work... :
| Code: | #t::
DetectHiddenWindows, On ;|Off
DetectHiddenText, On ;|Off
;ie = Primavera - Microsoft Internet Explorer ;what it needs to work on ultimately
ie = about:blank - Microsoft Internet Explorer ;localised test version
WinActivate %ie%
ControlSend, Edit1, javascript:function EnterTextAtField() {{}with (window.document.forms['dailyreportdetailform']) {{} elements['dailyReportMainCData.acceptedBy1'].value = "BETLOG"`; {}}{}}`; void(EnterTextAtField())`; {ENTER}, %ie%
Return |
If I use it on a blank explorer window (as above) it gives an error:
| Code: | Line: 1
Char: 30
Error: object required
Code: 0
URL: about:blank |
Which I assume just means it can't locate the right form...which is correct.
But when I change the %ie% line, log in and try it in primavera, it does nothing... absolutely nothing...and even the focus() code (as mentioned above) does nothing.
Excellent, I knew one of you guys could tell me where something useful was... i'll digest that soon. I spent about 12 hours yesterday reading pages from these forums :]
But have a feeling I have the right form name/index.
...i bet it's just some wrong syntax... i do that a lot, i'm just a hack, not a coder of anything.
Last edited by BETLOG on Wed Nov 29, 2006 6:46 am; edited 3 times in total |
|
| Back to top |
|
 |
BoBo Guest
|
Posted: Wed Nov 29, 2006 3:08 am Post subject: |
|
|
Check my ControlSendRaw post from today. I fought the same battle, with the outcome that most of the problem was about js typos which I wasn't able to identify because the browser responded nothing .
Good luck (I'm going to bed now )
Hey you edited your 'Bolivian herbs ..." statement to "Dr.Pepper"  |
|
| Back to top |
|
 |
BETLOG
Joined: 27 Nov 2006 Posts: 218 Location: Queensland, Australia
|
Posted: Wed Nov 29, 2006 4:34 am Post subject: |
|
|
interestingly:
when i tinker with this example:
http://www.autohotkey.com/forum/viewtopic.php?p=91717#91717
by inserting this:
javascript:window.document.formName.textID.value = "xxxxxx";void(0);
or
javascript:document.formName.textID.value = "yyyyyyyyy";void(0);
it works just fine.
But when i try a similar line in my Primavera window:
javascript:window.document.dailyreportdetailform.dailyReportMainCData.acceptedBy1.value="XXXX"
..it just does nothing.
I'm starting to get suspicious of this now:
dailyreportdetailform.dailyReportMainCData.acceptedBy1
Why does this element seem to have a form name in it...is this normal?
"dailyreportdetailform"is the name of the only form in the page/frame
"dailyReportMainCData.acceptedBy1" is the field i want to modify...yet it seems to reference another form?
What the...?! |
|
| Back to top |
|
 |
BoBo Guest
|
Posted: Wed Nov 29, 2006 8:37 am Post subject: |
|
|
| Quote: | | javascript:window.document.dailyreportdetailform.dailyReportMainCData.acceptedBy1.value="XXXX";void(0); | Will this do it? (No idea if the dot within dailyReportMainCData.acceptedBy1 is another issue) |
|
| 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
|