<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Question Re: SAP GUI with Python: Failed to get value from SAP using session.findById().text in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/sap-gui-with-python-failed-to-get-value-from-sap-using-session-findbyid/qaa-p/12243457#M4584373</link>
    <description>&lt;P&gt;&lt;SPAN class="mention-scrubbed"&gt;vincentthelibra&lt;/SPAN&gt; &lt;/P&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;your code works so far, I tried it on my test system. But there is an error in your string.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;"wnd[0]/usr/tabsTAXI_TABSTRIP_HEAD/tabpT\13/ssubSUBSCREEN_BODY:SAPMV45A:4312/sub8309:SAPMV45A:8309/txtVBAK-ZZCON"&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The string contains a backslash and it is necessary to escape them. Try it on this way...&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;"wnd[0]/usr/tabsTAXI_TABSTRIP_HEAD/tabpT\\13/ssubSUBSCREEN_BODY:SAPMV45A:4312/sub8309:SAPMV45A:8309/txtVBAK-ZZCON"&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;...and let us know your result.&lt;/P&gt;&lt;P&gt;Best regards&lt;BR /&gt;Stefan&lt;/P&gt;</description>
    <pubDate>Fri, 04 Dec 2020 04:44:47 GMT</pubDate>
    <dc:creator>Stefan-Schnell</dc:creator>
    <dc:date>2020-12-04T04:44:47Z</dc:date>
    <item>
      <title>SAP GUI with Python: Failed to get value from SAP using session.findById().text</title>
      <link>https://community.sap.com/t5/technology-q-a/sap-gui-with-python-failed-to-get-value-from-sap-using-session-findbyid/qaq-p/12243454</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;
  &lt;P&gt;I've just started using python to automate SAP GUI scripting (have been using VBA for that). However, it wouldnt work when I was trying to extract data from SAP.&lt;/P&gt;
  &lt;P&gt;In this case I was trying to get the value contract number in T-code VA03-Additional Data B.&lt;/P&gt;
  &lt;P&gt;I suppose this is probably little things i have completely ignored but would be good if someone can point it out...&lt;/P&gt;
  &lt;P&gt;It seems this particular field cannot be found by Python. However i tried the same method and it worked with VBA very well.&lt;/P&gt;
  &lt;P&gt;Here's the code:&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;# Import modules
import sys
import win32com.client


# SAP function
def sapconnection():
    try:

        SapGuiAuto = win32com.client.GetObject("SAPGUI")
        if not type(SapGuiAuto) == win32com.client.CDispatch:
            return

        application = SapGuiAuto.GetScriptingEngine
        if not type(application) == win32com.client.CDispatch:
            SapGuiAuto = None
            return

        connection = application.Children(0)
        if not type(connection) == win32com.client.CDispatch:
            application = None
            SapGuiAuto = None
            return

        session = connection.Children(0)
        if not type(session) == win32com.client.CDispatch:
            connection = None
            application = None
            SapGuiAuto = None
            return

        # Check VC number
        session.findById("wnd[0]").maximize()
        session.findById("wnd[0]/tbar[0]/okcd").text = "/nva03"
        session.findById("wnd[0]").sendVKey(0)
        session.findById("wnd[0]/usr/ctxtVBAK-VBELN").text = soNbr  #HERE IS WHERE I PUT THE SO
        session.findById("wnd[0]").sendVKey(0)
        session.findById("wnd[0]/mbar/menu[2]/menu[1]/menu[14]/menu[1]").select()
        #HERE IS WHERE IT THROWS AN ERROR
        vc = session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_HEAD/tabpT\13/ssubSUBSCREEN_BODY:SAPMV45A:4312/sub8309:SAPMV45A:8309/txtVBAK-ZZCON").text

    except:
        #print(sys.exc_info()[0])
        print(sys.exc_info())

    finally:
        session = None
        connection = None
        application = None
        SapGuiAuto = None

#main
if __name__ == "__main__":
    sapconnection()&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 01 Dec 2020 20:45:42 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/sap-gui-with-python-failed-to-get-value-from-sap-using-session-findbyid/qaq-p/12243454</guid>
      <dc:creator>former_member716327</dc:creator>
      <dc:date>2020-12-01T20:45:42Z</dc:date>
    </item>
    <item>
      <title>Re: SAP GUI with Python: Failed to get value from SAP using session.findById().text</title>
      <link>https://community.sap.com/t5/technology-q-a/sap-gui-with-python-failed-to-get-value-from-sap-using-session-findbyid/qaa-p/12243455#M4584371</link>
      <description>&lt;P&gt;Thank you for
visiting SAP Community to get answers to your questions. Since you're new in
asking questions here, I recommend that you familiarize yourself with &lt;A href="https://community.sap.com/resources/questions-and-answers"&gt;https://community.sap.com/resources/questions-and-answers&lt;/A&gt;
(if you haven't already), as it provides tips for preparing questions that draw
responses from our members.&lt;/P&gt;&lt;P&gt;Should you wish, you
can revise your question now by selecting Actions, then Edit.&lt;/P&gt;&lt;P&gt;Finally, if you're
hoping to connect with readers, please consider adding a picture to your
profile. Here's how you do it: &lt;A href="https://www.youtube.com/watch?v=F5JdUbyjfMA&amp;amp;list=PLpQebylHrdh5s3gwy-h6RtymfDpoz3vDS"&gt;https://www.youtube.com/watch?v=F5JdUbyjfMA&amp;amp;list=PLpQebylHrdh5s3gwy-h6RtymfDpoz3vDS&lt;/A&gt;
. By personalizing your profile with a photo of you, you encourage readers to
respond.&lt;/P&gt;&lt;P&gt;Best regards&lt;/P&gt;&lt;P&gt;Mariah&lt;/P&gt;&lt;P&gt;SAP Community
moderator&lt;/P&gt;</description>
      <pubDate>Tue, 01 Dec 2020 20:46:11 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/sap-gui-with-python-failed-to-get-value-from-sap-using-session-findbyid/qaa-p/12243455#M4584371</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2020-12-01T20:46:11Z</dc:date>
    </item>
    <item>
      <title>Re: SAP GUI with Python: Failed to get value from SAP using session.findById().text</title>
      <link>https://community.sap.com/t5/technology-q-a/sap-gui-with-python-failed-to-get-value-from-sap-using-session-findbyid/qaa-p/12243456#M4584372</link>
      <description>&lt;P&gt;What error message do you get?&lt;/P&gt;&lt;P&gt;Could you check whether the issue is about getting the menu object, or calling the method?&lt;/P&gt;</description>
      <pubDate>Wed, 02 Dec 2020 06:44:01 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/sap-gui-with-python-failed-to-get-value-from-sap-using-session-findbyid/qaa-p/12243456#M4584372</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2020-12-02T06:44:01Z</dc:date>
    </item>
    <item>
      <title>Re: SAP GUI with Python: Failed to get value from SAP using session.findById().text</title>
      <link>https://community.sap.com/t5/technology-q-a/sap-gui-with-python-failed-to-get-value-from-sap-using-session-findbyid/qaa-p/12243457#M4584373</link>
      <description>&lt;P&gt;&lt;SPAN class="mention-scrubbed"&gt;vincentthelibra&lt;/SPAN&gt; &lt;/P&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;your code works so far, I tried it on my test system. But there is an error in your string.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;"wnd[0]/usr/tabsTAXI_TABSTRIP_HEAD/tabpT\13/ssubSUBSCREEN_BODY:SAPMV45A:4312/sub8309:SAPMV45A:8309/txtVBAK-ZZCON"&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The string contains a backslash and it is necessary to escape them. Try it on this way...&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;"wnd[0]/usr/tabsTAXI_TABSTRIP_HEAD/tabpT\\13/ssubSUBSCREEN_BODY:SAPMV45A:4312/sub8309:SAPMV45A:8309/txtVBAK-ZZCON"&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;...and let us know your result.&lt;/P&gt;&lt;P&gt;Best regards&lt;BR /&gt;Stefan&lt;/P&gt;</description>
      <pubDate>Fri, 04 Dec 2020 04:44:47 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/sap-gui-with-python-failed-to-get-value-from-sap-using-session-findbyid/qaa-p/12243457#M4584373</guid>
      <dc:creator>Stefan-Schnell</dc:creator>
      <dc:date>2020-12-04T04:44:47Z</dc:date>
    </item>
    <item>
      <title>Re: SAP GUI with Python: Failed to get value from SAP using session.findById().text</title>
      <link>https://community.sap.com/t5/technology-q-a/sap-gui-with-python-failed-to-get-value-from-sap-using-session-findbyid/qaa-p/12243458#M4584374</link>
      <description>&lt;P&gt;I think it was a "control ID not found" type of error. but it seems, like Stefan said below, to be a simple error of not escaping the backslash... will try again with the correct string... thanks anyway.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Dec 2020 09:58:04 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/sap-gui-with-python-failed-to-get-value-from-sap-using-session-findbyid/qaa-p/12243458#M4584374</guid>
      <dc:creator>former_member716327</dc:creator>
      <dc:date>2020-12-04T09:58:04Z</dc:date>
    </item>
    <item>
      <title>Re: SAP GUI with Python: Failed to get value from SAP using session.findById().text</title>
      <link>https://community.sap.com/t5/technology-q-a/sap-gui-with-python-failed-to-get-value-from-sap-using-session-findbyid/qaa-p/12243459#M4584375</link>
      <description>&lt;P&gt;Thanks this is exactly the mistake...I knew it would be a very basic mistake. &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Dec 2020 10:28:42 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/sap-gui-with-python-failed-to-get-value-from-sap-using-session-findbyid/qaa-p/12243459#M4584375</guid>
      <dc:creator>former_member716327</dc:creator>
      <dc:date>2020-12-04T10:28:42Z</dc:date>
    </item>
  </channel>
</rss>

