Jump to content
Zaoka

SAP WEBI log on replace file IE.au3

Recommended Posts

I'm trying to create script that would login on my SAP WEBI "web page" and replace some uploaded excel files. But i'm having problem on even the log in.

These are user fill elements with Firefox Inspector

<input type="text" id="_id0:logon:CMS" name="_id0:logon:CMS">
<input type="text" id="_id0:logon:USERNAME" name="_id0:logon:USERNAME">
<input type="password" id="_id0:logon:PASSWORD" name="_id0:logon:PASSWORD">

LogOnButton

<input type="submit" id="_id0:logon:logonButton" value="Log On" class="logonButtonNoHover logon_button_no_hover" onmouseover="this.className = 'logonButtonHover logon_button_hover';" onmouseout="this.className = 'logonButtonNoHover logon_button_no_hover';">

 

 

My example, I tried _IEGetObjByName and _IEGetObjById but the script only open page but will not even fill out the form

 
#include <IE.au3>

Call("signIn")

Func signIn()
    Global $oIE = _IECreate("http://192.xxx.xxx.xx:xxx/BOE/BI")
    Sleep (5000)

    Local $server = _IEGetObjByName($oIE, "_id0:logon:CMS")
    Local $username = _IEGetObjByName($oIE, "_id0:logon:USERNAME")
    Local $password = _IEGetObjByName($oIE, "_id0:logon:PASSWORD")
    Local $button = _IEGetObjById($oIE, "_id0:logon:logonButton")

    _IEFormElementSetValue($server, "TestServer:1000")
    _IEFormElementSetValue($username, "MyUserName")
    _IEFormElementSetValue($password, "MyPass")

;  THIS PART ABOUT BUTTON CLICK I DONT UNDERSTAND AT ALL

    $sSelector = "body > div:nth-of-type(2) > div > div:nth-of-type(3) > div > table > tbody > tr > td > table > tbody > tr > td > table > tbody > tr:nth-of-type(1) > td > div > div:nth-of-type(1) > form > div:nth-of-type(5) > button"
    
    $signInUC = $oIE.document.QuerySelector($sSelector)

    _IEAction($signInUC, "click")

EndFunc   ;==>signIn

 

I would be very grateful for any help

Share this post


Link to post
Share on other sites

QuerySelector is based on CSS lexical patterns. See this site for more information.

But first, lets try to understand why the form is not filled.  Do you have any frame within this page ?

Share this post


Link to post
Share on other sites

I think @Nine has identified the issue. Try this modified code --

#include <IE.au3>

signIn()

Func signIn()
    Global $oIE = _IECreate("http://192.xxx.xxx.xx:xxx/BOE/BI")
    Sleep (5000)

    Local $oFrame = _IEFrameGetObjByName($oIE, "servletBridgeIframe")
    Local $server = _IEGetObjByName($oFrame, "_id0:logon:CMS")
    Local $username = _IEGetObjByName($oFrame, "_id0:logon:USERNAME")
    Local $password = _IEGetObjByName($oFrame, "_id0:logon:PASSWORD")
    Local $button = _IEGetObjById(oFrame, "_id0:logon:logonButton")

    _IEFormElementSetValue($server, "TestServer:1000")
    _IEFormElementSetValue($username, "MyUserName")
    _IEFormElementSetValue($password, "MyPass")
    _IEAction($button, "click") 

EndFunc   ;==>signIn

If this doesn't work, then show us the results from the Scite output panel.

 

Share this post


Link to post
Share on other sites
13 minutes ago, Danp2 said:

I think @Nine has identified the issue. Try this modified code --

#include <IE.au3>

signIn()

Func signIn()
    Global $oIE = _IECreate("http://192.xxx.xxx.xx:xxx/BOE/BI")
    Sleep (5000)

    Local $oFrame = _IEFrameGetObjByName($oIE, "servletBridgeIframe")
    Local $server = _IEGetObjByName($oFrame, "_id0:logon:CMS")
    Local $username = _IEGetObjByName($oFrame, "_id0:logon:USERNAME")
    Local $password = _IEGetObjByName($oFrame, "_id0:logon:PASSWORD")
    Local $button = _IEGetObjById(oFrame, "_id0:logon:logonButton")

    _IEFormElementSetValue($server, "TestServer:1000")
    _IEFormElementSetValue($username, "MyUserName")
    _IEFormElementSetValue($password, "MyPass")
    _IEAction($button, "click") 

EndFunc   ;==>signIn

If this doesn't work, then show us the results from the Scite output panel.

 

Tnx, yes this helped, menage to log on successful .

I only change small typo

Local $button = _IEGetObjById($oFrame, "_id0:logon:logonButton")

I will now try to write rest of code...

Share this post


Link to post
Share on other sites

Next step is to navigate to file and confirm... but this is too complicated for me

Click number 1

<a id="yui-gen0-1-label" tabindex="-1" class="yui-accordion-toggle" role="tab" aria-expanded="false" title="Expand My Documents">My Documents<span class="indicator" role="presentation"></span></a>
Click number 2
<a href="javascript:void(0);" class="ygtvspacer" tabindex="-1" role="presentation" aria-labelledby="ygtvcontentel8" aria-level="0">&nbsp;</a>

Click number 3

<span id="MyDocs_treeView_treeNode14_name" style="cursor:pointer; white-space:nowrap;"><img id="MyDocs_treeView_treeNodeIcon_14" src="../../../shared/pluginIconLoader/Folder/SI_PLUGIN_ICON_1.gif" style="width:16px;height:16px;" alt="Folder" border="0">&nbsp;Excel&nbsp;</span>

Click number 4

<div id="ListingURE_detailView_listColumn_6_0_1" style="overflow: hidden; padding: 2px 0px 2px 4px;" aria-describedby="ListingURE_detailView_mainTooltip">Nihad Konzum</div>

Right click on Click number 4

<a href="#" class="yuimenuitemlabel yuimenuitemlabel-selected" role="menuitem" tabindex="-1">Replace File</a>

Click Browse for path for local document, it opens windows to navigate to local PC file

<input type="file" styleid="fileUploadFileName" name="filename" size="53" class="rowInput" onchange="javascript:validateFileName();" oncontextmenu="return false;" contenteditable="false">

Click Replace for confirm

<input type="button" class="inputButton" id="replaceButton" onclick="javascript:onSubmit();" value="Replace">

 

Is possible to translate code from FireFox add on IMacros or some other macro addon.

This is from IMacros

VERSION BUILD=10021450
URL GOTO=http://192.000.000.00:0000/BOE/BI
FRAME F=4
TAG POS=1 TYPE=A ATTR=ID:yui-gen0-1-label
TAG POS=1 TYPE=A ATTR=TXT:
TAG POS=1 TYPE=SPAN ATTR=ID:MyDocs_treeView_treeNode14_name
TAG POS=1 TYPE=DIV ATTR=ID:ListingURE_detailView_listColumn_6_0_1
TAG POS=1 TYPE=A ATTR=TXT:Replace<SP>File
FRAME F=8
TAG POS=1 TYPE=INPUT:FILE FORM=NAME:uploadForm ATTR=NAME:filename CONTENT=C:\fakepath\Zaoka<SP>file.xlsx
TAG POS=1 TYPE=INPUT:BUTTON ATTR=ID:replaceButton
FRAME F=1
TAG POS=1 TYPE=BUTTON ATTR=ID:yui-gen11-button

Selenium IDe

{
  "id": "7d4bedfb-f2a5-42bb-9a15-219980022696",
  "version": "2.0",
  "name": "test",
  "url": "http://192.000.000.00:000",
  "tests": [{
    "id": "04809fe1-31b7-4129-8631-b9b0fb727a87",
    "name": "test",
    "commands": [{
      "id": "92892413-697b-4961-bdaa-61e95414707d",
      "comment": "",
      "command": "open",
      "target": "/BOE/BI",
      "targets": [],
      "value": ""
    }, {
      "id": "716be288-deae-48fb-bb1a-87e8f841a341",
      "comment": "",
      "command": "setWindowSize",
      "target": "1731x819",
      "targets": [],
      "value": ""
    }, {
      "id": "2942b610-e01e-4297-a235-d9ff3091b647",
      "comment": "",
      "command": "selectFrame",
      "target": "index=0",
      "targets": [
        ["index=0"]
      ],
      "value": ""
    }, {
      "id": "436daac0-2471-4c69-8595-74286a5005fd",
      "comment": "",
      "command": "selectFrame",
      "target": "index=2",
      "targets": [
        ["index=2"]
      ],
      "value": ""
    }, {
      "id": "4d389015-331e-43f8-aa50-44a71fb2ef00",
      "comment": "",
      "command": "click",
      "target": "id=yui-gen0-1-label",
      "targets": [
        ["id=yui-gen0-1-label", "id"],
        ["linkText=My Documents", "linkText"],
        ["css=#yui-gen0-1-label", "css:finder"],
        ["xpath=//a[contains(text(),'My Documents')]", "xpath:link"],
        ["xpath=//a[@id='yui-gen0-1-label']", "xpath:attributes"],
        ["xpath=//ul[@id='yui-gen0']/li/a", "xpath:idRelative"],
        ["xpath=//a", "xpath:position"],
        ["xpath=//a[contains(.,'My Documents')]", "xpath:innerText"]
      ],
      "value": ""
    }, {
      "id": "509465eb-1e6f-4ff8-b371-b81424cbb56f",
      "comment": "",
      "command": "click",
      "target": "css=#ygtvt8 > .ygtvspacer",
      "targets": [
        ["css=#ygtvt8 > .ygtvspacer", "css:finder"],
        ["xpath=//td[@id='ygtvt8']/a", "xpath:idRelative"],
        ["xpath=//a[contains(@href, 'javascript:void(0);')]", "xpath:href"],
        ["xpath=//td/a", "xpath:position"],
        ["xpath=//a[contains(.,' ')]", "xpath:innerText"]
      ],
      "value": ""
    }, {
      "id": "357afefb-d5aa-4821-8f50-f5f7ac6a3f96",
      "comment": "",
      "command": "click",
      "target": "id=MyDocs_treeView_treeNode14_name",
      "targets": [
        ["id=MyDocs_treeView_treeNode14_name", "id"],
        ["css=#MyDocs_treeView_treeNode14_name", "css:finder"],
        ["xpath=//span[@id='MyDocs_treeView_treeNode14_name']", "xpath:attributes"],
        ["xpath=//a[@id='ygtvlabelel14']/span", "xpath:idRelative"],
        ["xpath=//div[2]/table/tbody/tr/td[3]/a/span", "xpath:position"],
        ["xpath=//span[contains(.,' Excel ')]", "xpath:innerText"]
      ],
      "value": ""
    }, {
      "id": "db98c788-a34c-4493-b51c-7adf9b8d7a72",
      "comment": "",
      "command": "click",
      "target": "id=ListingURE_detailView_listColumn_6_0_1",
      "targets": [
        ["id=ListingURE_detailView_listColumn_6_0_1", "id"],
        ["css=#ListingURE_detailView_listColumn_6_0_1", "css:finder"],
        ["xpath=//div[@id='ListingURE_detailView_listColumn_6_0_1']", "xpath:attributes"],
        ["xpath=//tr[@id='ListingURE_detailView_listNode6_0']/td[2]/div", "xpath:idRelative"],
        ["xpath=//tr[7]/td[2]/div", "xpath:position"]
      ],
      "value": ""
    }, {
      "id": "aec7d26a-dbb0-4a00-9fb0-26fae8e6dae5",
      "comment": "",
      "command": "click",
      "target": "linkText=Replace File",
      "targets": [
        ["linkText=Replace File", "linkText"],
        ["css=#yui-gen13 > .yuimenuitemlabel", "css:finder"],
        ["xpath=//a[contains(text(),'Replace File')]", "xpath:link"],
        ["xpath=//li[@id='yui-gen13']/a", "xpath:idRelative"],
        ["xpath=(//a[contains(@href, '#')])[11]", "xpath:href"],
        ["xpath=//li[5]/a", "xpath:position"],
        ["xpath=//a[contains(.,'Replace File')]", "xpath:innerText"]
      ],
      "value": ""
    }, {
      "id": "b8ad3099-7a45-4c61-8611-456e97047226",
      "comment": "",
      "command": "selectFrame",
      "target": "relative=parent",
      "targets": [
        ["relative=parent"]
      ],
      "value": ""
    }, {
      "id": "176b376b-27f3-4930-a023-7e8da8f95184",
      "comment": "",
      "command": "selectFrame",
      "target": "index=5",
      "targets": [
        ["index=5"]
      ],
      "value": ""
    }, {
      "id": "6cbe4e9f-fea0-4eb5-bf52-3c79280c072b",
      "comment": "",
      "command": "click",
      "target": "name=filename",
      "targets": [
        ["name=filename", "name"],
        ["css=.rowInput", "css:finder"],
        ["xpath=//input[@name='filename']", "xpath:attributes"],
        ["xpath=//input[16]", "xpath:position"]
      ],
      "value": ""
    }, {
      "id": "3fd5e9b0-8635-4457-88b4-dfb469def453",
      "comment": "",
      "command": "type",
      "target": "name=filename",
      "targets": [
        ["name=filename", "name"],
        ["css=.rowInput", "css:finder"],
        ["xpath=//input[@name='filename']", "xpath:attributes"],
        ["xpath=//input[16]", "xpath:position"]
      ],
      "value": "C:\\fakepath\\consume.xlsx"
    }, {
      "id": "74c3dbbc-25f8-45fc-a68b-c5a15cae4db9",
      "comment": "",
      "command": "click",
      "target": "id=replaceButton",
      "targets": [
        ["id=replaceButton", "id"],
        ["css=#replaceButton", "css:finder"],
        ["xpath=//input[@id='replaceButton']", "xpath:attributes"],
        ["xpath=//span[@id='buttonPanel']/input", "xpath:idRelative"],
        ["xpath=//span/input", "xpath:position"]
      ],
      "value": ""
    }, {
      "id": "da5037a1-fd60-4dd5-bc0a-9a29e3c634b9",
      "comment": "",
      "command": "selectFrame",
      "target": "relative=parent",
      "targets": [
        ["relative=parent"]
      ],
      "value": ""
    }, {
      "id": "392ecd1d-4dfa-4459-988d-8591552eaea6",
      "comment": "",
      "command": "click",
      "target": "id=yui-gen11-button",
      "targets": [
        ["id=yui-gen11-button", "id"],
        ["css=#yui-gen11-button", "css:finder"],
        ["xpath=//button[@id='yui-gen11-button']", "xpath:attributes"],
        ["xpath=//span[@id='yui-gen11']/span/button", "xpath:idRelative"],
        ["xpath=//button", "xpath:position"],
        ["xpath=//button[contains(.,'OK')]", "xpath:innerText"]
      ],
      "value": ""
    }]
  }],
  "suites": [{
    "id": "ea5b6a1a-a96b-4947-be97-1a54a167217a",
    "name": "Default Suite",
    "persistSession": false,
    "parallel": false,
    "timeout": 300,
    "tests": ["04809fe1-31b7-4129-8631-b9b0fb727a87"]
  }],
  "urls": ["http://192.000.000.00:000/"],
  "plugins": []
}

 

Edited by Zaoka

Share this post


Link to post
Share on other sites
4 hours ago, Zaoka said:

Next step is to navigate to file and confirm... but this is too complicated for me

Yes... that is a complicated series of events.  Here are a few pointers to hopefully get you started --

  • Assuming there are still frames involved, so you will probably need switch to the correct frame first
  • Items 1, 3 & 4 all have IDs, so you should be able to use _IEGetObjById and _IEAction to perform the clicks
  • Item 2 doesn't have an ID, but maybe you can use _IELinkGetCollection with an index to obtain the desired element
  • To Right click on an element, try something like this --
    $oElement.fireEvent("oncontextmenu")

    where $oElement is the target element

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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Pured
      I am looking to create a script which refreshes/reads a webpage every few seconds. My goal is to see if the page has changed, then I will send myself a notification that the webpage has been updated.
       
      However, rather than downloading the entire webpage every single time, is there a way to check when the webpage last updated?
       
      If not, is there away to partially download/read html source until a specific tag is hit?
       
      Goal: I would like to increase my poll rate and not excessively waste data.
    • By Mr_Microphone
      Alright, I may be an idiot.
      Three years ago, I wrote a program that pushed component information to a secure site via their API. I went back to add some attributes and (here's the idiot part) ended up losing the  source code and my modified code does not quite work. I have the compiled version that works minus the new attributes, so I know that their system has not changed. I stripped the larger program down from 3,000 lines to the part that is broken, but I am stumped. This was one of my first scripts, so it heavily leverages examples and isn't as pretty as I'd like it to be.
      Be gentle. 
      The program / script creates a new records as expected, but for some reason, I cannot access information in the response, which I need for a later step.
      I use Charles, a web debugging proxy tool so I can see the request and the response and both are as expected. Also, when I write to log file, the JSON reply is exactly what I expect and need, but when I try to do anything with the http body, it seems to be blank. 
      Here is the script minus  the URL and token:
      #include <Array.au3> #include <Curl.au3> #include <MsgBoxConstants.au3> #include <json.au3>  ; this was added as an alternate way to read the data Global $WM_serial_number = "WM20745001" Global $wm_component_status_id = "10" Global $wm_manufacturer ="Multi-Tech" Global $wm_model = "MTR-LAT1-B07" Global $cellular_carrier_id = "3" Global $iccid_esn = "89010303300012345678" Global $ip_address = "192.168.2.11" Global $NewIDNumber     Local $Curl = Curl_Easy_Init()     Local $Html = $Curl ; any number as identify     Local $Header = $Curl + 1 ; any number as identify     Local $HtmlFile = "cURL_Request.html"     Local $File = FileOpen($HtmlFile, 2 + 16)     Local $Slist = Curl_Slist_Append(0, "content-type: multipart/form-data; boundary=---011000010111000001101001")     $Slist = Curl_Slist_Append($Slist, "authorization: Token token=" & $Token)     Curl_Easy_Setopt($Curl, $CURLOPT_PROXY, "127.0.0.1") ; needed to use Charles web debugging proxy     Curl_Easy_Setopt($Curl, $CURLOPT_PROXYPORT, 8888) ; needed to use Charles     Curl_Easy_Setopt($Curl, $CURLOPT_HTTPHEADER, $Slist) ;     Curl_Easy_Setopt($Curl, $CURLOPT_URL, $Server & "wireless_module" & "s")     Curl_Easy_Setopt($Curl, $CURLOPT_SSL_VERIFYPEER, 0)     Curl_Easy_Setopt($Curl, $CURLOPT_TIMEOUT, 30)     Curl_Easy_Setopt($Curl, $CURLOPT_WRITEDATA, $Html)     Curl_Easy_Setopt($Curl, $CURLOPT_WRITEFUNCTION, Curl_FileWriteCallback())     Curl_Easy_Setopt($Curl, $CURLOPT_WRITEDATA, $File)     Local $HttpPost = ""     Local $LastItem = ""         Curl_FormAdd($HttpPost, $LastItem, $CURLFORM_COPYNAME, "wireless_module" & "[serial_number]", $CURLFORM_COPYCONTENTS, $WM_serial_number, $CURLFORM_END)         Curl_FormAdd($HttpPost, $LastItem, $CURLFORM_COPYNAME, "wireless_module" & "[component_status_id]", $CURLFORM_COPYCONTENTS, $wm_component_status_id, $CURLFORM_END)         Curl_FormAdd($HttpPost, $LastItem, $CURLFORM_COPYNAME, "wireless_module" & "[manufacturer]", $CURLFORM_COPYCONTENTS, $wm_manufacturer, $CURLFORM_END)         Curl_FormAdd($HttpPost, $LastItem, $CURLFORM_COPYNAME, "wireless_module" & "[model]", $CURLFORM_COPYCONTENTS, $wm_model, $CURLFORM_END)         Curl_FormAdd($HttpPost, $LastItem, $CURLFORM_COPYNAME, "wireless_module" & "[cellular_carrier_id]", $CURLFORM_COPYCONTENTS, $cellular_carrier_id, $CURLFORM_END)         Curl_FormAdd($HttpPost, $LastItem, $CURLFORM_COPYNAME, "wireless_module" & "[iccid_esn]", $CURLFORM_COPYCONTENTS, $iccid_esn, $CURLFORM_END)         Curl_FormAdd($HttpPost, $LastItem, $CURLFORM_COPYNAME, "wireless_module" & "[ip_address]", $CURLFORM_COPYCONTENTS, $ip_address, $CURLFORM_END)         ; submit         Curl_Easy_Setopt($Curl, $CURLOPT_HTTPPOST, $HttpPost)         Local $Code = Curl_Easy_Perform($Curl)         If $Code = $CURLE_OK Then         ConsoleWrite("Content Type: " & Curl_Easy_GetInfo($Curl, $CURLINFO_CONTENT_TYPE) & @LF)         ConsoleWrite("Download Size: " & Curl_Easy_GetInfo($Curl, $CURLINFO_SIZE_DOWNLOAD) & @LF)         MsgBox(0, 'Html', BinaryToString(Curl_Data_Get($Html))) ; this is something I threw in for debugging, expecting to see SOMETHING. Returns nothing         MsgBox(0, 'Header', BinaryToString(Curl_Data_Get($Header))) ; this is something I threw in for debugging, expecting to see SOMETHING. Returns nothing         Local $response = Curl_Easy_GetInfo($Curl, $CURLINFO_RESPONSE_CODE)             If $response = "409" Then $response = "Failed due to a conflict."             If $response = "200" Then $response = "Was NOT created."             If $response = "201" Then $response = "Was created."             ; read the ID that was assigned and store it         $NewIDNumber = StringRight(StringLeft(BinaryToString(Curl_Data_Get($Html)), 10), 4) ; this DID work, but now it doesn't. An old compiled version still works ;~         Global $JsonObject = json_decode($Html); another debugging attempt. Did not use json functions previously and the program worked without it. ;~         Global $NewIDNumber = json_get($JsonObject, '.id')         ConsoleWrite(@CRLF &'! id:' & $NewIDNumber & @CRLF & @CRLF)    ; debugging feedback         MsgBox(0, $response, $wm_serial_number & " new ID = " & $NewIDNumber); debugging feedback         If $Code <> $CURLE_OK Then ConsoleWrite(Curl_Easy_StrError($Code) & @LF)             Local $Data = BinaryToString(Curl_Data_Get($Curl))             Curl_Easy_Cleanup($Curl)             Curl_Data_Cleanup($Curl)             Curl_Data_Cleanup($Header)             Curl_Data_Cleanup($Html)             Curl_FormFree($HttpPost)             Curl_slist_free_all($Slist)             curl_easy_reset($Curl)             FileClose($File)             ConsoleWrite(@LF)         EndIf  This is the captured request (minus the host and token)
      POST /api/v2/wireless_modules HTTP/1.1 Host: api. Accept: */* authorization: Token token= Content-Length: 942 Expect: 100-continue content-type: multipart/form-data; boundary=---011000010111000001101001; boundary=------------------------9adb0d87c7ea5061 --------------------------9adb0d87c7ea5061 Content-Disposition: form-data; name="wireless_module[serial_number]" WM20745001 --------------------------9adb0d87c7ea5061 Content-Disposition: form-data; name="wireless_module[component_status_id]" 10 --------------------------9adb0d87c7ea5061 Content-Disposition: form-data; name="wireless_module[manufacturer]" Multi-Tech --------------------------9adb0d87c7ea5061 Content-Disposition: form-data; name="wireless_module[model]" MTR-LAT1-B07 --------------------------9adb0d87c7ea5061 Content-Disposition: form-data; name="wireless_module[cellular_carrier_id]" 3 --------------------------9adb0d87c7ea5061 Content-Disposition: form-data; name="wireless_module[iccid_esn]" 89010303300012345678 --------------------------9adb0d87c7ea5061 Content-Disposition: form-data; name="wireless_module[ip_address]" 192.168.2.11 --------------------------9adb0d87c7ea5061-- and the captured response
      HTTP/1.1 201 Created Date: Sun, 04 Apr 2021 00:12:18 GMT Server: Apache Cache-Control: max-age=0, private, must-revalidate Access-Control-Allow-Origin: not-allowed Vary: Accept-Encoding Access-Control-Max-Age: 1728000 X-XSS-Protection: 1; mode=block X-Request-Id: 71cfcf36-6020-48a6-a822-d2b393a27b69 Access-Control-Allow-Credentials: true Access-Control-Allow-Methods: PUT, OPTIONS, GET, POST ETag: W/"25d97fe8a9387cb4b9029a9e62b0bfa2" X-Frame-Options: SAMEORIGIN, SAMEORIGIN X-Runtime: 0.344005 X-Content-Type-Options: nosniff Access-Control-Request-Method: * X-Powered-By: Phusion Passenger 5.2.1 Strict-Transport-Security: max-age=63072000; includeSubDomains; preload Location: /wireless_modules/3195 Status: 201 Created Connection: close Transfer-Encoding: chunked Content-Type: application/json; charset=utf-8 X-Charles-Received-Continue: HTTP/1.1 100 Continue {"id":3195,"model":"MTR-LAT1-B07","serial_number":"WM20745001","manufacturer":"Multi-Tech","mfg_date":null,"iccid_esn":"89010303300012345678","ip_address":"192.168.2.11","purchase_order":null,"supplier":null,"cellular_carrier_id":3,"component_status_id":10,"component_status":{"id":10,"name":"Hold","description":"Available- Held for specific use"},"custom_attributes":[{"name":"Deactivated","type":"Boolean","value":false},{"name":"Port 3001","type":"Boolean","value":false}],"comments":[]}  
      Also attached is the log file. I need to read the id value. Clearly, it is arriving back to cURL, since it is being written out to the log, but I cannot seem to get to it within the code. 
      It is established that I may be an idiot, but this idiot has wasted days in non-billable hours trying to figure out what should be a simple glitch.
      Help???
       
      cURL_Request.html
    • By Hermes
      I have an html table that displays data along with an excel spreadsheet that has the same data as the html table. I am wanting to only match the Title column in my html table with the Title column in my Excel spreadsheet. If the titles match, click on the Edit hyperlink and continue to loop to next row. The issue I'm experience is its not matching correctly. So far  i've written the codes below:
      <table border="1" class="test"> <tr> <th> UniqueID</th> <th> Title</th> <th> UserID</th> <th> Address</th> <th> Gender </th> </tr> <tr> <td> 1 </td> <td> Title1 </td> <td> 12345 </td> <td> Manila </td> <td> <span> Male </span> </td> </tr> <tr> <td align="center" colspan="5"> <a href="#" class="testlink">Edit</a> </td> </tr> <tr> <td> 2 </td> <td> Title2 </td> <td> 67891 </td> <td> Valenzuela </td> <td> <span> Female </span> </td> </tr> <tr> <td align="center" colspan="5" > <a href="#" class="testlink">Edit</a> </td> </tr> <tr> <td> 3 </td> <td> Title3 </td> <td> 88888 </td> <td> Ohio </td> <td> <span> Male </span> </td> </tr> <tr> <td align="center" colspan="5" > <a href="#" class="testlink">Edit</a> </td> </tr> <tr> <td> 4 </td> <td> Title4 </td> <td> 77777 </td> <td> California </td> <td> <span> Female </span> </td> </tr> <tr> <td align="center" colspan="5" > <a href="#" class="testlink">Edit</a> </td> </tr> <tr> <td> 5 </td> <td> Title5 </td> <td> 33333 </td> <td> Arizona </td> <td> <span> Male </span> </td> </tr> <tr> <td align="center" colspan="5" > <a href="#" class="testlink">Edit</a> </td> </tr> </table> #Include "Chrome.au3" #Include "wd_core.au3" #Include "wd_helper.au3" #Include "Excel.au3" #Include "_HtmlTable2Array.au3" #Include "Array.au3" Local $sDesiredCapabilities, $sSession SetupChrome() _WD_Startup() $sSession = _WD_CreateSession($sDesiredCapabilities) _WD_LoadWait($sSession) _WD_Navigate($sSession, "index.html") Sleep(6000) Local $oExcel = _Excel_Open() Local $oWorkbook = _Excel_BookOpen($oExcel, "test.xlsx") ; Get the table element $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//table[@class='test']") ; Retrieve HTML $sHTML = _WD_ElementAction($sSession, $sElement, "Property", "outerHTML") ;Local $aTable = _HtmlTableGetWriteToArray($sHTML) Local $aArray1 = _Excel_RangeRead($oWorkbook,1,$oWorkbook.ActiveSheet.Usedrange.Columns("B:B")) Local $aArray2 = _HtmlTableGetWriteToArray($sHTML) ;_ArrayDisplay($aArray1) ;_ArrayDisplay($aArray2) For $i = UBound($aArray1) - 1 To 0 step - 1 For $j = UBound($aArray2) - 1 to 0 step - 1 If $aArray1[$i][1] == $aArray2[$j][1] Then _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, "//a[contains(@class,'testlink') or contains(text(),'Edit')]") $test1 = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//a[contains(@class,'testlink') or contains(text(),'Edit')]") _WD_ElementAction($sSession, $test1, 'click') ;_ArrayDisplay($aArray1) ;_ArrayDelete($aArray1 , $i) ;exitloop EndIf Next Next _WD_Shutdown() Func SetupChrome() _WD_Option('Driver', 'chromedriver.exe') _WD_Option('Port', 9515) _WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\chrome.log"') $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "args":["start-maximized","disable-infobars"]}}}}' EndFunc ;==>SetupChrome Would appreciate if anyone can provide tips, or point me in the right direction in doing it.
       
      test.xlsx
    • By mLipok
      In the past there was many questions about how to: "Automatic file upload using without user interaction"

      https://www.autoitscript.com/forum/topic/92907-ie-8-input-namenomfic-typefile-idnomfic/
      https://www.autoitscript.com/forum/topic/116899-cant-automate-input-typefile-tag-in-ie/?tab=comments#comment-815478
      https://www.autoitscript.com/forum/topic/14883-input-typefile/
      https://www.autoitscript.com/forum/topic/188708-how-to-set-the-value-of-an-input-typefile-element/
      https://www.autoitscript.com/forum/topic/91513-how-can-i-auto-set-file-path-for-input-file-in-ie/
      https://www.autoitscript.com/forum/topic/116899-cant-automate-input-typefile-tag-in-ie/
      https://www.autoitscript.com/forum/topic/169190-how-to-script-file-upload-button/
      https://www.autoitscript.com/forum/topic/145327-how-to-deal-with-ie-window-for-upload-a-fileinput-typefile/
      https://www.autoitscript.com/forum/topic/140482-internet-explorer-input-file-problem/
       
      I found solution here: 
      https://stackoverflow.com/questions/33253517/upload-a-file-via-input-input-in-html-form-with-vba
      and:
      https://www.motobit.com/tips/detpg_uploadvbsie/
      And I translate this code to AutoIt3 code:
      ; Upload file using http protocol And multipart/form-data ; v1.01 ; 2001 Antonin Foller, PSTRUH Software Global $oErrorHandler = ObjEvent("AutoIt.Error", _ErrFunc) do_vbsUpload() Func do_vbsUpload() #cs ; We need at least two arguments (File & URL) ConsoleWrite('- ' & @ScriptLineNumber & @CRLF) If $CmdLine[0] < 2 Then InfoEcho() ConsoleWrite('- ' & @ScriptLineNumber & @CRLF) ; Are some required objects missing? If StringInStr(CheckRequirements(), "Error") > 0 Then InfoEcho() ConsoleWrite('- ' & @ScriptLineNumber & @CRLF) Local $s_FileName, $s_DestURL, $s_FieldName $s_FieldName = "FileField" ; Default field name For $i_argCounter = 1 To $CmdLine[0] ConsoleWrite('+ '& $i_argCounter& ' >> ' & $CmdLine[$i_argCounter] & @CRLF) Select Case $i_argCounter = 1 ;~ $s_FileName = $CmdLine[$i_argCounter] $s_FileName = @ScriptFullPath Case $i_argCounter = 2 $s_DestURL = $CmdLine[$i_argCounter] Case $i_argCounter = 3 $s_FieldName = $CmdLine[$i_argCounter] EndSelect Next UploadFile($s_DestURL, $s_FileName, $s_FieldName) #ce UploadFile('http://www.dobeash.com/test.html', @ScriptFullPath, 'fileExample') EndFunc ;==>do_vbsUpload ; ******************* upload - begin ; Upload file using input type=file Func UploadFile($s_DestURL, $s_FileName, $s_FieldName) ; Boundary of fields. ; Be sure this string is Not In the source file Const $Boundary = "---------------------------0123456789012" ; Get source file As a binary data. Local $d_FileContents = GetFile($s_FileName) ; Build multipart/form-data document Local $s_FormData = BuildFormData($d_FileContents, $Boundary, $s_FileName, $s_FieldName) ; Post the data To the destination URL IEPostBinaryRequest($s_DestURL, $s_FormData, $Boundary) EndFunc ;==>UploadFile ; Build multipart/form-data document with file contents And header info Func BuildFormData($d_FileContents, $Boundary, $s_FileName, $s_FieldName) Const $s_ContentType = "application/upload" ; The two parts around file contents In the multipart-form data. Local $s_Pre = "--" & $Boundary & @CRLF & mpFields($s_FieldName, $s_FileName, $s_ContentType) Local $s_Po = @CRLF & "--" & $Boundary & "--" & @CRLF ; Build form data using recordset binary field Const $i_adLongVarBinary = 205 Local $oRS = ObjCreate("ADODB.Recordset") ; https://docs.microsoft.com/en-us/sql/ado/reference/ado-api/append-method-ado?view=sql-server-ver15 $oRS.Fields.Append("b", $i_adLongVarBinary, StringLen($s_Pre) + BinaryLen($d_FileContents) + StringLen($s_Po)) $oRS.Open() $oRS.AddNew() ; Convert Pre string value To a binary data Local $i_LenData = StringLen($s_Pre) $oRS("b").AppendChunk(StringToMB($s_Pre) & StringToBinary(Chr(0))) $s_Pre = $oRS("b").GetChunk($i_LenData) $oRS("b") = "" ; Convert Po string value To a binary data $i_LenData = StringLen($s_Po) $oRS("b").AppendChunk(StringToMB($s_Po) & StringToBinary(Chr(0))) $s_Po = $oRS("b").GetChunk($i_LenData) $oRS("b") = "" ; Join Pre & $d_FileContents & Po binary data $oRS("b").AppendChunk($s_Pre) $oRS("b").AppendChunk($d_FileContents) $oRS("b").AppendChunk($s_Po) $oRS.Update() Local $s_FormData = $oRS("b") $oRS.Close() Return $s_FormData EndFunc ;==>BuildFormData ; sends multipart/form-data To the URL using IE Func IEPostBinaryRequest($s_URL, $s_FormData, $Boundary) ; Create InternetExplorer Local $oIE = ObjCreate("InternetExplorer.Application") ; You can uncoment Next line To see form results $oIE.Visible = True ; Send the form data To $s_URL As POST multipart/form-data request $oIE.Navigate($s_URL, '', '', $s_FormData, _ "Content-Type: multipart/form-data; boundary=" & $Boundary & @CRLF) While $oIE.Busy Wait(1, "Upload To " & $s_URL) WEnd ; Get a result of the script which has received upload ;~ On Error Resume Next Local $s_IE_InnerHTML = $oIE.Document.body.innerHTML MsgBox(0, 'TEST #' & @CRLF & @ScriptLineNumber, $s_IE_InnerHTML) $oIE.Quit() Return $s_IE_InnerHTML EndFunc ;==>IEPostBinaryRequest ; Infrormations In form field header. Func mpFields($s_FieldName, $s_FileName, $s_ContentType) Local $s_MPTemplate = _ ; template For multipart header 'Content-Disposition: form-data; name="{field}";' & _ 'FileName="{file}"' & @CRLF & _ 'Content-Type: {ct}' & @CRLF & @CRLF & _ '' Local $s_Out $s_Out = StringReplace($s_MPTemplate, "{field}", $s_FieldName) $s_Out = StringReplace($s_Out, "{file}", $s_FileName) $s_Out = StringReplace($s_Out, "{ct}", $s_ContentType) Return $s_Out EndFunc ;==>mpFields Func Wait($i_Seconds, $s_Message) MsgBox(64, '', $s_Message, $i_Seconds) EndFunc ;==>Wait ; Returns file contents As a binary data Func GetFile($s_FileName) Local $oStream = ObjCreate("ADODB.Stream") $oStream.Type = 1 ; Binary $oStream.Open() $oStream.LoadFromFile($s_FileName) Local $d_GetFile = $oStream.Read() $oStream.Close() Return $d_GetFile EndFunc ;==>GetFile ; Converts OLE string To multibyte string Func StringToMB($S) Local $I, $B For $I = 1 To StringLen($S) $B &= StringToBinary(Asc(StringMid($S, $I, 1))) Next Return $B EndFunc ;==>StringToMB ; ******************* upload - end ; ******************* Support ; Basic script info Func InfoEcho() Local $sMsg = _ "Upload file using http And multipart/form-data" & @CRLF & _ "Copyright (C) 2001 Antonin Foller, PSTRUH Software" & @CRLF & _ "use" & @CRLF & _ "[cscript|wscript] fupload.vbs file $s_URL [fieldname]" & @CRLF & _ " file ... Local file To upload" & @CRLF & _ " $s_URL ... $s_URL which can accept uploaded data" & @CRLF & _ " fieldname ... Name of the source form field." & @CRLF & _ @CRLF & CheckRequirements() & @CRLF & _ "" ConsoleWrite('! ' & $sMsg & @CRLF) EndFunc ;==>InfoEcho ; Checks If all of required objects are installed Func CheckRequirements() Local $sMsg = _ "This script requires some objects installed To run properly." & @CRLF & _ CheckOneObject("ADODB.Recordset") & @CRLF & _ CheckOneObject("ADODB.Stream") & @CRLF & _ CheckOneObject("InternetExplorer.Application") & @CRLF & _ "" Return $sMsg ; $sMsgBox $sMsg EndFunc ;==>CheckRequirements ; Checks If the one object is installed. Func CheckOneObject($sClassName) Local $sMsg ObjCreate($sClassName) If @error = 0 Then $sMsg = "OK" Else $sMsg = "Error:" & @error EndIf Return $sClassName & " - " & $sMsg EndFunc ;==>CheckOneObject ; ******************* Support - end ; User's COM error function. Will be called if COM error occurs Func _ErrFunc(ByRef $oError) ; Do anything here. ConsoleWrite(@ScriptName & " (" & $oError.scriptline & ") : ==> COM Error intercepted !" & @CRLF & _ @TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _ @TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _ @TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _ @TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _ @TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _ @TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _ @TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _ @TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _ @TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF & @CRLF) EndFunc ;==>_ErrFunc  
      But I miss something and the code not works as intendend.
      Please join and contribute, in solving this issue, as this will be handy for entire community.
      @mLipok
       
      btw.
      I think that this may be realated to ChrB() which I simply translate to StringToBinary()
      Especialy this :
      StringToBinary(Chr(0))) could be the main issue.
      But for now I'm tired and going to sleep.
      Hope maybe tomorrow somebody solve this issue.
       
×
×
  • Create New...