Jump to content

IE.au3 and href:"javascript..." links


ssubirias3
 Share

Recommended Posts

Hi guys! I have an .aspx site needing some automation that's giving me a challenge. I've made some solid progress but need some help connecting the dots on this one. I fully realize the problem is my lack of knowledge, but I've killed enough time getting no where on this item. Hoping someone smarter than me can lend a hand.

I've tried getting the information from various GetObj and GetCollection commands within the IE.au3 UDF. _IESubmitForm and _IEAction have not worked for me (beyond logging into the website). I finally got the EDIT link to respond using _IELinkClickByText, but the Item inside the ListBoxCamps numbered 123 needs to be selected prior to clicking EDIT. Here's some of the web page source file that might lend insight on what I'm missing.

Thanks in advance for the help!

<form name="form1" method="post" action="Default.aspx" id="form1">
<div>
<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTE0NDM0Mzc ... tLruB" />
</div>

<script type="text/javascript">
//<![CDATA[
var theForm = document.forms['form1'];
if (!theForm) {
    theForm = document.form1;
}
function __doPostBack(eventTarget, eventArgument) {
    if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
        theForm.__EVENTTARGET.value = eventTarget;
        theForm.__EVENTARGUMENT.value = eventArgument;
        theForm.submit();
    }
}
//]]>
</script>

<td align="left">
                                <select size="4" name="ListBoxCamps" id="ListBoxCamps" style="height:200px;width:230px;">
    <option value="123">Item (needs to be selected)</option>
</select>
                            </td>

<td align="center" width="15%">
                    <a id="LinkButtonEdit" href="java script:__doPostBack('LinkButtonEdit','')">Edit</a>
                </td>
                <td align="right" width="40%">
                    <a id="LinkButtonCancel" href="java script:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;LinkButtonCancel&quot;, &quot;&quot;, false, &quot;&quot;, &quot;../Default.aspx&quot;, false, true))">Back</a>
                </td>
Link to comment
Share on other sites

Have you taken a look at _IEFormElementOptionselect() ?

Also, make sure you are using something like DebugBar to examine the source insted of the browser View Source option so that you see the source after all client-side processing is complete.

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

Have you taken a look at _IEFormElementOptionselect() ?

Also, make sure you are using something like DebugBar . . .

Thanks Dale! I pulled down and installed DebugBar from your signature, helpful tool.

About _IEFormElementOptionselect(), that worked like a charm . . . almost. I incorporated the code which appears to selecte the item (123) as needed. However when the script clicks the Edit link, the results are not the same if I had selected Item manually then clicked the Edit link. What appears to be happening is the webpage is responding with a selected Item (123), but the value (target/argument) isn't passed to the javascript as part of the __doPostBack function defined in the webpage.

Using the site source as provided above and the following au3 excerpt, I'm hoping you can suggest addition tweaks that will get me rolling.

Again thanks in advance!! If needed, I can send you the URL, credentials, and actual code I'm using in a pm.

_IENavigate($oIE, $url2)
sleep(3000)
$oForm = _IEFormGetObjByName($oIE, "form1")
$oSelect = _IEFormElementGetObjByName($oForm, "ListBoxCamps")
_IEFormElementOptionselect($oSelect, "123", 1, "byValue")
Sleep(3000)
_IELinkClickByText($oIE, "Edit")

Edit Link href:

<a id="LinkButtonEdit" href="java script:__doPostBack('LinkButtonEdit','')">Edit</a>

java script:

<script type="text/javascript">
//<![CDATA[
var theForm = document.forms['form1'];
if (!theForm) {
    theForm = document.form1;
}
function __doPostBack(eventTarget, eventArgument) {
    if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
        theForm.__EVENTTARGET.value = eventTarget;
        theForm.__EVENTARGUMENT.value = eventArgument;
        theForm.submit();
    }
}
//]]>
</script>

Link to comment
Share on other sites

  • 2 weeks later...

. . . the code selects the item (123) as needed. However when the script clicks the Edit link, the results are not the same if I had selected Item manually then clicked the Edit link. What appears to be happening is the webpage is responding with a selected Item (123), but the value (target/argument) isn't passed to the javascript as part of the __doPostBack function defined in the webpage. . .

_IENavigate($oIE, $url2)
sleep(3000)
$oForm = _IEFormGetObjByName($oIE, "form1")
$oSelect = _IEFormElementGetObjByName($oForm, "ListBoxCamps")
_IEFormElementOptionselect($oSelect, "123", 1, "byValue")
Sleep(3000)
_IELinkClickByText($oIE, "Edit")

Edit Link href:

<a id="LinkButtonEdit" href="java script:__doPostBack('LinkButtonEdit','')">Edit</a>

** BUMP **

@Dale - your thoughts as to why the webpage doesn't respond correctly after IEFormElementOptionselect() selects the listbox item compared to either a manual or MouseClick() selection?

I've passed you the URL and credentials in a PM. The site isn't plain ole html like the IE Example pages. Instead it has a good amount of javascript tucked in the pages and else where. Thanks again for your help!!

Link to comment
Share on other sites

In the HTML you posted, the href calling the __doPostBack script is passing only the name of the Edit button element, not the value of the selection element:

<a id="LinkButtonEdit" href="java script:__doPostBack('LinkButtonEdit','')">Edit</a>

and the __doPostBack script is only using the values passed to it.

I see nothing in what you posted that would make this work differently between an _IELinkClickByText and a MouseClick.

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

. . . I see nothing in what you posted that would make this work differently between an _IELinkClickByText and a MouseClick.

Makes sense and I agree this doesn't make sense why it doesn't work.

I've have even EXITed the script immediately after the "Item" is selected by _IEFormElementOptionselect($oSelect, "123", 1, "byValue") and manually clicking the "Edit" link. However it doesn't advance to the next page, but instead puts me back at the root menu as if a hidden error has occurred.

This leads me to believe that _IEFormElementOptionselect($oSelect, "123", 1, "byValue") isn't working correctly with this website.

I've sent you the URL and credentials via PM, could you please take a peek. Using DebugBar and viewing the HTTP session information, I can see a difference in traffic between the following methods:

  • selecting the listbox "Item" and the "Edit" link manually or with MouseClick()
  • selecting the listbox "Item" with IE.au3 and selecting the "Edit" link manually, MouseClick(), or IE.au3
Edited by ssubirias3
Link to comment
Share on other sites

I no longer have your PM.

Suggest you use DebugBar to examine the source after manually selecting the selection item to see if it is different and work backwards. It could be that another event is reguired to be fired on the OPTION SELECT -- IE.au3 files the onclick and onchange events if I remember properly...

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...