Jump to content

How to set value in Web-Page DropDown box, using FF3.au3?


 Share

Recommended Posts

Hello, I want to set the values in 3 DropDownBoxes on a web-page. Html for 1st box is:

<select class="standardFont quickTransferDropDownSelect" id="ctl00_MainPageContent_char1_DropDownList" name="ctl00$MainPageContent$char1$DropDownList">

<option value="-1" selected="selected">&nbsp;Please select&nbsp;</option>

<option value="4">&nbsp;a&nbsp;</option>

<option value="5">&nbsp;b&nbsp;</option>

...

I'm working on web-page SavedAs local file so not to cause lots of failed logins before I get it right.

I tried: _FFSetValue:

For $chix = 1 To 3

$ans = 4

$id = StringFormat("ctl00_MainPageContent_char%1d_DropDownList", $chix)

_FFSetValue($ans, $id, "id")

The console window shows

__FFSend: try{window.content.top.document.getElementById('ctl00_MainPageContent_char1_DropDownList').value='i'}catch(e){'_FFCmd_Err';};

__FFRecv: i

So that's alright? but no visible change on web-page or in html viewed with FireBug.

I tried sending _FFClick, and then down-arrows, but nothing to the DropDown, and he web-page moves down.

_FFClick ($id, "id", 0, 0)

send("{Down}")

__FFSend: try{FFau3.simulateEvent(FFau3.WCD.getElementById('ctl00_MainPageContent_char1_DropDownList'),'MouseEvents','click');}catch(e){'_FFCmd_Err';};

__FFRecv: 1

I tried getting the whole page html, modify, write back:

$html = _FFReadHTML("body")

$html = StringReplace($html,"Help","Hello World")

$html = StringReplace($html,"-1","3")

_FFWriteHTML($html)

Again, __FFRecv: 1, and no error messages, but nothing changes on the page.

Any suggestions appreciated.

Richard.

Link to comment
Share on other sites

Hello,

if you wanna change the value of one of the options, you can try this:

$sOption1 = _FFXPath("//select[id='ctl00_MainPageContent_char1_DropDownList']//option[1]","",9) ; first option
_FFObj($sOption1, "value", "1")

or want you select one option? Then look at this:

http://english.documentation.ff-au3.thorsten-willert.de/ff_functions/_FFFormOptionselect.php

Stilgar

Edited by Stilgar
Link to comment
Share on other sites

Well, I said it worked, and it does for most values. For the numbers 0..9 it works, accepts number or string. For the letters a..z most work but some don't. I made the prog send 0..9,a..z and the ones that fail are a,c,e,l,s,t. When it fails the DropDownBox shows "Please Select". For each setting the console has the same 3 lines, for fail or not, shown for 9,a,b.

I tried various other things, sending "A" - nomatch. Reverse the order of sending - same ones fail. Manually pull down each value - all normal. All the other options for $sOptionMode (but sending the value) - all fail. All 3 Boxes - the same.

The html for the DropDownBox shows the options in a very peculiar order, maybe there's an alpha-sort implied somewhere. I've included the whole html for it below. I can't see any link between the order and the ones that fail. e.g. the options for k,l,m are in order with values 14,15,16, and l fails.

Richard.

For $anix = 0 to 9 + 26
    $chix = 1
    $id = StringFormat("ctl00_MainPageContent_char%1d_DropDownList", $chix)
    if $anix <= 9 then
        $ans = $anix
    Else
        $ans = chr(asc("a") -1 + $anix - 9)
    EndIf
    ConsoleWrite(StringFormat("D1 -%s-  \n", $ans))
    _FFFormOptionselect($id, "id", $ans, "text")
    Sleep(800)
Next

Console:

...

D1 -9-

__FFSend: FFau3.xpath=null;try{FFau3.xpath=FFau3.WCD.evaluate("//form[1]//select[@id='ctl00_MainPageContent_char1_DropDownList']//option[contains(.,'9')]",FFau3.WCD,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue.selected=true;}catch(e){'_FFXPath_Error: '+e;};

__FFRecv: 1

D1 -a-

__FFSend: FFau3.xpath=null;try{FFau3.xpath=FFau3.WCD.evaluate("//form[1]//select[@id='ctl00_MainPageContent_char1_DropDownList']//option[contains(.,'a')]",FFau3.WCD,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue.selected=true;}catch(e){'_FFXPath_Error: '+e;};

__FFRecv: 1

D1 -b-

__FFSend: FFau3.xpath=null;try{FFau3.xpath=FFau3.WCD.evaluate("//form[1]//select[@id='ctl00_MainPageContent_char1_DropDownList']//option[contains(.,'b')]",FFau3.WCD,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue.selected=true;}catch(e){'_FFXPath_Error: '+e;};

__FFRecv: 1

...

DropDownBox html:

<select class="standardFont quickTransferDropDownSelect" id="ctl00_MainPageContent_char1_DropDownList" name="ctl00$MainPageContent$char1$DropDownList">
        <option value="-1" selected="selected">&nbsp;Please select&nbsp;</option>
        <option value="4">&nbsp;a&nbsp;</option>
        <option value="5">&nbsp;b&nbsp;</option>
        <option value="6">&nbsp;c&nbsp;</option>
        <option value="7">&nbsp;d&nbsp;</option>
        <option value="8">&nbsp;e&nbsp;</option>
        <option value="9">&nbsp;f&nbsp;</option>
        <option value="10">&nbsp;g&nbsp;</option>
        <option value="11">&nbsp;h&nbsp;</option>
        <option value="12">&nbsp;i&nbsp;</option>
        <option value="13">&nbsp;j&nbsp;</option>
        <option value="14">&nbsp;k&nbsp;</option>
        <option value="15">&nbsp;l&nbsp;</option>
        <option value="16">&nbsp;m&nbsp;</option>
        <option value="17">&nbsp;n&nbsp;</option>
        <option value="18">&nbsp;o&nbsp;</option>
        <option value="19">&nbsp;p&nbsp;</option>
        <option value="20">&nbsp;q&nbsp;</option>
        <option value="21">&nbsp;r&nbsp;</option>
        <option value="22">&nbsp;s&nbsp;</option>
        <option value="23">&nbsp;t&nbsp;</option>
        <option value="24">&nbsp;u&nbsp;</option>
        <option value="25">&nbsp;v&nbsp;</option>
        <option value="26">&nbsp;w&nbsp;</option>
        <option value="27">&nbsp;x&nbsp;</option>
        <option value="28">&nbsp;y&nbsp;</option>
        <option value="29">&nbsp;z&nbsp;</option>
        <option value="30">&nbsp;0&nbsp;</option>
        <option value="31">&nbsp;1&nbsp;</option>
        <option value="32">&nbsp;2&nbsp;</option>
        <option value="33">&nbsp;3&nbsp;</option>
        <option value="34">&nbsp;4&nbsp;</option>
        <option value="35">&nbsp;5&nbsp;</option>
        <option value="0">&nbsp;6&nbsp;</option>
        <option value="1">&nbsp;7&nbsp;</option>
        <option value="2">&nbsp;8&nbsp;</option>
        <option value="3">&nbsp;9&nbsp;</option>
    </select>

Link to comment
Share on other sites

Alright, that's quite funny.

I tried &nbsp;9&nbsp; didn't work:

D1 -&nbsp;9&nbsp;-

__FFSend: FFau3.xpath=null...

__FFRecv: _FFXPath_Error: ... contains(.,'&nbsp;9&nbsp;')]", ...

_FFXPath ==> No match: sin...

and I tried trimming off the ; and a few other chars. Nothing worked.

I've tried the "value" and that works. I don't wanted to use that because the mapping might change, and it makes the code different for every web-page possibly different for each DropDownBox.

I will try _FFXPath, and change "Please select" to "=" then it won't match.

Thanks again,

Richard

Link to comment
Share on other sites

I have to use several tedious sites at home an work, it's for all of them. I was trying to keep it non-specific, generally useful, and not say exactly what this is. If you like puzzles there are several clues in the content and I won't spoil it by telling.

Richard.

Link to comment
Share on other sites

I thought I/we'd done it but no. The next setback is that the web-site changes the mapping of the DropDown box index values each time. Alright, I've read the html found out how its mapped, get the index value that I want, done. The problem is that the saved file A.html accepts the write, but the real web-page doesn't.

Consolewrite(stringformat("D3 -%s%- -%s-\n", $id, $ddvix))
_FFFormOptionselect($id, "id", $ddvix, "value")
]

Console output for success in C:\a.html
D3 -ctl00_MainPageContent_char1_DropDownList%- -29-
__FFSend: FFau3.xpath=null;try{FFau3.xpath=FFau3.WCD.evaluate("//form[1]//select[@id='ctl00_MainPageContent_char1_DropDownList']//option[@value='29']",FFau3.WCD,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue.selected=true;}catch(e){'_FFXPath_Error: '+e;};
__FFRecv: 1
Fail on-line
D3 -ctl00_MainPageContent_char1_DropDownList%- -28-
__FFSend: FFau3.xpath=null;try{FFau3.xpath=FFau3.WCD.evaluate("//form[1]//select[@id='ctl00_MainPageContent_char1_DropDownList']//option[@value='28']",FFau3.WCD,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue.selected=true;}catch(e){'_FFXPath_Error: '+e;};
__FFRecv: _FFXPath_Error: TypeError: FFau3.WCD.evaluate("//form[1]//select[@id='ctl00_MainPageContent_char1_DropDownList']//option[@value='28']", FFau3.WCD, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue is null

So what is the difference on-line? The css file is missing offline, so it looks different, that does not matter? Something else? On-Change functions that are failing? Have they defended the page against repl?

I'm nearly defeated on this, going back to MouseClick and Send.

Any comments appreciated.

Richard

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...