2

I am trying to automatize some SAP Job monitoring with Python. I want to create a script that should do the following:

Connect and login the SAP environment -> Open SM37 transaction -> Send job parameters (name-user-from-to) -> Read the output and store it into a database.

I don't know about any module or library that allow me to do that. So I checked the WEBGUI is already enabled. I am able to open the environment through a Browser. A browsing module should allows me to do everything I need. Tried with Mechanize and RoboBrowser. It works but the WEBGUI runs a lot of javascript for renderize and those modules doesn't handle javascript.

There is one more shot: Selenium. I was able to connect and login to the environment. But when trying to select an element from new page (main menu), Selenium cannot locate the element.

Printing the sourcecode I realized that the Main Menu site is rendered with javascript. The sourcecode doesn't contains the element at all, only the title ("Welcome "). That means the login was successfull.

I read a lot of posts asking for this, and everybody reccommend to use WebDriverWait with some explicit conditions.

Tried this, didn't work:

driver.get("http://mysapserver.domain:8000/sap/bc/gui/sap/its/webgui?sap-client=300&sap-language=ES")
wait = WebDriverWait(driver, 30)
element = wait.until(EC.presence_of_element_located((By.ID, 'ToolbarOkCode')))

EDIT:

There are two sourcecodes: SC-1 is the one that Selenium reads. SC-2 is the one that appears once the javascript renders the site (the one from "Inspect Element").

The full SC-1 is this: https://pastebin.com/5xURA0Dc

The SC-2 for the element itself is the following:

<input id="ToolbarOkCode" ct="I" lsdata="{0:'ToolbarOkCode',1:'Comando',4:200,13:'150px',23:true}" lsevents="{Change:[{ClientAction:'none'},{type:'TOOLBARINPUTFIELD'}],Enter:[{ClientAction:'submit',PrepareScript:'return\x20its.XControlSubmit\x28\x29\x3b',ResponseData:'delta',TransportMethod:'partial'},{Submit:'X',type:'TOOLBARINPUTFIELD'}]}" type="text" maxlength="200" tabindex="0" ti="0" title="Comando" class="urEdf2TxtRadius urEdf2TxtEnbl urEdfVAlign" value="" autocomplete="on" autocorrect="off" name="ToolbarOkCode" style="width:150px;">

Still can't locate the element. How can I solve it? Thanks in advance.

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
  • check if the element is in inside frame – Gaurang Shah Jul 31 '17 at 12:42
  • The sourcecode doesn't contains the element at all, neither in an iframe. Only the title ("Welcome "). That means the login was successful. –  Jul 31 '17 at 12:50
  • check using firebug add-on of firefox. check the code of particular element. – Gaurang Shah Jul 31 '17 at 12:55
  • I have edited the original post with the sourcecode. You can check there. –  Jul 31 '17 at 13:43
  • 1
    there are atleast 3 frames with ids, `ITSFRAME1` , `ITSFRAME2` and `ITSTERMFRAME`. you need to figure out in which frame your element is. Again use, firebug and inspect element. – Gaurang Shah Jul 31 '17 at 13:50
  • You are right! It was all inside ITSFRAME1. I moved into the iframe and then I was able to select the control. Thank you! –  Jul 31 '17 at 14:53
  • Post the solution as answer or delete the question, don't put "[SOLVED]" into the title. – deceze Jul 31 '17 at 14:58

1 Answers1

2

The solution was to go into the iframe that containts the renderized html (with the control).

driver2.get("http://mysapserver.domain:8000/sap/bc/gui/sap/its/webgui?sap-client=300&sap-language=ES")
iframe = driver2.find_elements_by_tag_name('iframe')[0]
driver2.switch_to_default_content()
driver2.switch_to_frame(iframe)
driver2.find_element_by_id("ToolbarOkCode").send_keys("SM37")
driver2.find_element_by_id("ToolbarOkCode").send_keys(Keys.ENTER)