Jump to content

Can't read style element


Recommended Posts

I'm trying to create an autoPop tool for AliExpress. When I get to their address page, there are a number of input fields. There are also two drop downs. One is for the country and, depending on what you select, the other dropdown appears with city names or, a standard input box is visible to add a city (See the images). So if I select "United States" the other dropdown is visible with all the states. If I select "France", the input box is visible to enter a French city. Seems cool enough but I'm really struggling trying to get this to work.

This is my test code to work all this out:

#include <MsgBoxConstants.au3>
#include <IE.au3>

Local $StartPos
Local $oIE = _IECreate("https://shoppingcart.aliexpress.com/order/confirm_order.htm?objectId=1792065272&from=aliexpress&countryCode=US&shippingCompany=EMS&provinceCode=&cityCode=&promiseId=&itemCondition=&=556&aeOrderFrom=main_detail&skuAttr=&quantity=1")
    If @error Then Exit MsgBox(16, "openURL Error", @CRLF & "@error = " & @error & ", @extended = " & @extended)
    ;If $bVerbose == true Then MsgBox(0, "openURL", "IECreate Object Created")
;Get the Collections
$oInputs = _IETagNameGetCollection($oIE, "input"); Input Fields
$oSelects = _IETagNameGetCollection($oIE, "select"); Select Fields

;Loop through the Selects
For $oSelect In $oSelects
    If $oSelect.name = "country" Then _IEFormElementOptionSelect($oSelect, "France", 1, "byText",1)
Next

;Loop through the inputs
For $oInput In $oInputs
    If $oInput.name = "email" Then $oInput.Value = "test@test.com"
    If $oInput.name = "contactPerson"  Then $oInput.Value = "My Full Name"
    If $oInput.name = "address"  Then $oInput.Value = "123 Anystreet"
    If $oInput.name = "address2"  Then $oInput.Value = "NA"
    If $oInput.name = "province"  Then
        MsgBox(0, "","$oInput.name = " & $oInput.name &@CRLF &"$oInput.style = " & $oInput.style &@CRLF &"$oInput.type = " & $oInput.type&@CRLF &"$oInput.maxLength = " & $oInput.maxlength)
        $oInput.Value = "FrenchyLand"
    EndIf

    If $oInput.name = "city" Then $oInput.Value = "AnyTown"
    If $oInput.name = "zip" Then $oInput.Value = "12345"
    If $oInput.name = "mobileNo" Then $oInput.Value = "1-415-555-1212"
Next

So I open the page on AliExpress and get an   "input" collection and a "select" Collection
I first loop through the Selects until I find "country" and then select "France"
I then loop through all the inputs and put the information in the correct inputs.

When the country is one that AliExpress knows the states or provinces for,  they swap Styles between the input box and the dropdown  to either "display: inline-block;" or "display: none;" which hides one, or the other (See the AliExpDOM Image).

Problem #1: When I use the "_IEFormElementOptionSelect($oSelect, "France", 1, "byText",1)" To make the dropdown selection, It selects it but does not invoke the widget to change the second dropdown to an input box.

Problem #2: I thought a possible solution would be to read the Style of the input box and based on the value, either place text in the input box or go to the dropdown and make a selection. I can't seem to read the Style attribute from the collection ie: $oInput.style returns nothing.

Any help here would be greatly appreciated. If I figure out a solution before and answer here, I will publish it here for anyone else who might be struggling with these kinds of things

Thanks

 

 

 

 

AliExpWithDropDowns.png

AliExpWithInputBox.png

AliExpDOM.png

Link to comment
Share on other sites

  • 2 weeks later...
On 2/10/2016 at 5:01 PM, TimothyGirard said:

Problem #1: When I use the "_IEFormElementOptionSelect($oSelect, "France", 1, "byText",1)" To make the dropdown selection, It selects it but does not invoke the widget to change the second dropdown to an input box.

I tried doing it in FF in many ways, and it just does not respond like it should, with JS. I guess some kind of js library is the problem?

Here's an idea:

#include <MsgBoxConstants.au3>
#include <IE.au3>
#include <Array.au3>
#include <WinAPI.au3>

Local $oIE = _IECreate("https://shoppingcart.aliexpress.com/order/confirm_order.htm?objectId=1792065272&from=aliexpress&countryCode=US&shippingCompany=EMS&provinceCode=&cityCode=&promiseId=&itemCondition=&=556&aeOrderFrom=main_detail&skuAttr=&quantity=1")

$oCountry = _IEGetObjByName($oIE, "country")
$oBoundingClientRect = $oCountry.getBoundingClientRect()

$tRect = _WinAPI_GetWindowRect($oIE.hwnd)
$aPos = ControlGetPos(HWnd($oIE.hwnd), Default, "[CLASS:Internet Explorer_Server]")
MouseClick("primary", $tRect.Left+$aPos[0]+$oBoundingClientRect.left+(($oBoundingClientRect.right-$oBoundingClientRect.left)/2), $tRect.Top+$aPos[1]+$oBoundingClientRect.top+(($oBoundingClientRect.bottom-$oBoundingClientRect.top)/2), 1, 0)
Sleep(100)
ControlSend(HWnd($oIE.hwnd), Default, "[CLASS:Internet Explorer_Server]", "{HOME}", 0)
Sleep(100)
ControlSend(HWnd($oIE.hwnd), Default, "[CLASS:Internet Explorer_Server]", "{DOWN}", 0)
Sleep(100)
ControlSend(HWnd($oIE.hwnd), Default, "[CLASS:Internet Explorer_Server]", "{DOWN}", 0)
Sleep(100)
ControlSend(HWnd($oIE.hwnd), Default, "[CLASS:Internet Explorer_Server]", "{DOWN}", 0)
Sleep(100)
ControlSend(HWnd($oIE.hwnd), Default, "[CLASS:Internet Explorer_Server]", "{DOWN}", 0)
Sleep(100)
ControlSend(HWnd($oIE.hwnd), Default, "[CLASS:Internet Explorer_Server]", "{ENTER}", 0)

I tried getting the position of the option elements, but apparently that might be impossible :), so here's the next best thing.

On 2/10/2016 at 5:01 PM, TimothyGirard said:

Problem #2: I thought a possible solution would be to read the Style of the input box and based on the value, either place text in the input box or go to the dropdown and make a selection. I can't seem to read the Style attribute from the collection ie: $oInput.style returns nothing.

$oInput.style is only for local styles set with the style attribute, i think. Also depending on the IE version only properties within the style object can be set and read, like $oInput.style.backgroundColor

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

×
×
  • Create New...