TimothyGirard

Can't read style element

2 posts in this topic

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

Share this post


Link to post
Share on other sites



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

Share this post


Link to post
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

  • Similar Content

    • mjolnirmarkiv
      By mjolnirmarkiv
      Hi!
      Does anyone have any idea why Test() returns 0, while Test2() returns 1?
      #include <IE.au3> MsgBox(0, "", Test() & " " & Test2()) Func Test() Local $oHTML = ObjCreate("HTMLFILE") $oHTML.body.innerHTML = FileRead("Test.html") Return IsObj($oHTML.getElementsByClassName("example")) EndFunc Func Test2() Local $oIE = _IEAttach("", "instance", 1) Return IsObj($oIE.document.getElementsByClassName("example")) EndFunc Sample Test.html I open in IE before testing:
      <!DOCTYPE html> <html> <body> <p class="example"></p> <div class="example"></div> </body> </html> I'm receiving html text in a response to http request, I need to parse it fast and easy, getElementsByClassName would have been ideal. I'm using 3.3.12.0 version.
    • ADIN
      By ADIN
      When at some page i access by  IE.au3 appears javascript alert all my code stops and i cant do nothing. Is there any way to stop executing javascript at this page or any way to force autoit to click "OK" when this alert appears?
       
      _IENavigate($oIE, "www.example.com") _IELoadWait($oIE) ; site is loaded and alert appears Send("{ENTER}") ;i want to close alert, this command is not executed, whole script is freeze ; cant do nothing more here....  
    • ADIN
      By ADIN
      I want use _IEFormGetCollection to get form content which was generated by javascript
      Local $oIE = _IECreate("https://www.example.com/login.html") ;Open the login page Local $oSpans = _IETagNameGetCollection($oIE, "span") For $oSpan In $oSpans if $oSpan.innertext == "Login" Then _IEAction($oSpan, "click") EndIf Next ;click span which ganerate by javascript login form Local $oForm = _IEFormGetCollection($oIE, 0) ;get my form, but that was not on website after loading, appears after click button and this function cant see it Local $oEmail = _IEFormElementGetObjByName($oForm, "email") ; trying to parse form but cant _IEFormElementSetValue($oEmail, "example@gmail.com") ; _IEFormGetCollection dont see generated dynamically elements Is here any way to _IETagNameGetCollection read website content again after i inititate a javascript which generate additional content?
    • dumbledown
      By dumbledown
      Hi,
      I'm new to AutoIt but it looks great.
      I want to get the text from Internet Explorer when hovering the mouse over an image, the statusbargettext function appears to be the way to go.
      When running via a hotkey I return a blank, but the msgbox works. Do you know what I'm doing wrong?
      Thanks
      HotKeySet("!x", "RecordURL") ;wait for ALT-a keystroke While 1 ;loop forever to wait for the keypress Sleep(100) ;no need to kill the CPU WEnd Func RecordURL() #include <MsgBoxConstants.au3> AutoItSetOption("WinTitleMatchMode", 2) Local $sText = StatusbarGetText("Internet Explorer") MsgBox($MB_SYSTEMMODAL, "", "Internet Explorer's status bar says: " & $sText) EndFunc  
       
    • boooooom
      By boooooom
      I'm trying to get the HTML code after executing javascript in IE. Here is my code.
      $url = "http://example.com" $oIE = _IECreate($url) Sleep(3000) ;waiting for executing javascript. But useless. $oFrame = _IEFrameGetCollection($oIE, 0) $sCode &= _IEPropertyGet($oFrame, "innerhtml") & @CRLF Then, I get this error.
      "C:\Program Files (x86)\AutoIt3\Include\IE.au3" (2308) : ==> The requested action with this object has failed.: $oTemp = $oObject.document.body $oTemp = $oObject^ ERROR After executing javascript, when I view source in IE, there are HTML code like below.
      <html> <head> ... </head> <body> ... </body> </html> What should I do?