Jump to content

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

Link to comment
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 ?

Link to comment
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.

 

Link to comment
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...

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

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