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.

7
  • check if the element is in inside frame Commented Jul 31, 2017 at 12:42
  • The sourcecode doesn't contains the element at all, neither in an iframe. Only the title ("Welcome <user name>"). That means the login was successful. Commented Jul 31, 2017 at 12:50
  • check using firebug add-on of firefox. check the code of particular element. Commented Jul 31, 2017 at 12:55
  • I have edited the original post with the sourcecode. You can check there. Commented Jul 31, 2017 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. Commented Jul 31, 2017 at 13:50

1 Answer 1

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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.