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

    • 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?
    • MattG1991
      By MattG1991
      Hello all, 
      I've written a script that pulls info from some web pages, saves the results to variables, and prints it out to a Word document. I've tried to make this script work with a minimum of user interaction. I've noticed an issue happens when I run the script and I have another window set as active, like SciTE for example. It inserts an "ETX" character. I've done this with Notepad too. It displays an upside down L character. Any particular reason why? Unfortunately, I can't post any code. Basically, it gets a collection of tags, applies a test to find the values I want, then pulls the innerhtml from said tag. Then it assigns the results to a global variable.  Any help would be appreciated. 
    • CT83
      By CT83
      I send Pushbullet Updates (pushbullet.com) of my script using its native API and i have the following code to do the same, but in some cases my internet connection sometimes stops responding and the notification can't be send  using HTTP.send($sPD) methods,in such cases due to the lack of internet connection a runtime error (The requested action with this object has failed) is generated! This creates problems, as the stability of my script is affected. Is there a way to solve this problem?
      Func Send_Pushbullet($spTitle,$sBody,$GFPsh_Tk) Local $sPD = '{"type": "note", "title": "'&$spTitle&'","body": "'&$sBody&'"}' $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("POST", "https://api.pushbullet.com/v2/pushes", False) $oHTTP.setRequestHeader("Authorization", "Bearer " & $GFPsh_Tk) $oHTTP.SetRequestHeader("Content-Type", "application/json") $oHTTP.Send($sPD) $Result = $oHTTP.ResponseText ToolTip2("PushBullet :"&$Result) ToolTip2("PushBullet Sent - "&$spTitle&" : "&$sBody&" "&$GFPsh_Tk) EndFunc  
    • jonson1986
      By jonson1986
      Hello I'm trying to translate few text using below code, I found it working previously couple of months ago but Now these days it's not working at all and I'm getting below errors when I run the script and Array display at the end of text also not able to show any translated text instead of value 0 & 1;
      --> IE.au3 T3.0-2 Warning from function _IEGetObjById, $_IESTATUS_NoMatch (gt-res-data)
      --> IE.au3 T3.0-2 Error from function _IEPropertyGet, $_IESTATUS_InvalidDataType
      Here is code,
      #include <IE.au3> #include <Array.au3> Local $tag="* # * # *" Local $oIE=_IECreate("https://translate.google.com/#auto/es") Local $oForm=_IEFormGetCollection($oIE,0) Local $oQuery=_IEGetObjByName($oForm,"text") _IEFormElementSetValue($oQuery, $tag & @CR & "Hello World" & @CR & "This is a test" & @CR & $tag) _IEFormSubmit($oForm) _IELoadWait($oIE) Local $oText=_IEGetObjById($oIE,"gt-res-data") $lines=StringSplit(_IEPropertyGet($oText,"innerText"),@CRLF,1) _IEQuit($oIE) _ArrayDelete($lines,_ArraySearch($lines,$tag,1,0,0,1,0) & "-" & $lines[0]) _ArrayDelete($lines,"1-" & _ArraySearch($lines,$tag,1,0,0,1,1)) $lines[0]=UBound($lines)-1 _ArrayDisplay($lines)  
    • PunkoHead
      By PunkoHead
      Hi all,
      I am having an issue with a website that I want to automate.
      I have this menu and I want to click on the Custom button.

       
       
      The buttons with "inspect element" are: 
       

       
      The code that I tried is
      $sSearch = "Custom" $oFrame = _IEFrameGetObjByName($oIE, "options") $oDivs = _IETagNameGetCollection($oFrame, "ul") For $oDiv In $oDivs If String(_IEPropertyGet($oDiv, "InnerText")) = $sSearch Then _IEAction($oDiv, "click") ExitLoop EndIf Next I also tried with:
      $sMyString = "Custom" Local $oLinks = _IELinkGetCollection($oIE) For $oLink In $oLinks Local $sLinkText = _IEPropertyGet($oLink, "innerText") If StringInStr($sLinkText, $sMyString) Then _IEAction($oLink, "click") ExitLoop EndIf Next  
      However, these are not working. Any ideas?