cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

GUI SCRIPTING: GUI 770 changed SAP.HTMLControl / HTMLViewer / BrowserHandle ?

0 Likes
6,540

GUI SCRIPTING: GUI 770 changed SAP.HTMLControl / HTMLViewer / BrowserHandle ?

When we use the version 740, we can get a text from the 2nd window ( - normally it uses for information / caution / warning message) as below:

session.findById(id).BrowserHandle.document.all(0).innerText

However, after upgrade to version 770, we can not get anything from this command.

Just received the ERROR as BrowserHandle is [NONE] type object.

Could you please tell us How to get the TEXT which displayed in the 2nd (id = "wnd[1]", information / caution / warning) window?

Accepted Solutions (1)

Accepted Solutions (1)

FrankKrauseGUI
Product and Topic Expert
Product and Topic Expert

Hello Masa,

this issue has been fixed in patchlevel 3 of SAP GUI for Windows 7.70.
It was introduced when the HTML Control based on Edge (WebView2) was created.
See also SAP Note 3050103 - "SAP GUI HTML Control for windows: Scripting property BrowserHandle returns null"

Best regards,
Frank

0 Likes

Hello, Krause,

Thank you very much, now everything is very much clear!

Unfortunately, I could not reach the document of Note 3050103 ,

However, now I understand that I need to wait for SupGui will be updated...

Best regards,

Masa

Answers (1)

Answers (1)

Stefan-Schnell
Active Contributor
0 Likes

anh_masa

Hello Masa,
welcome in the SAP Community.

A normal dialog, like your case and the following example, ...

... could have more lines, here SPOP_TEXTLINE1 and SPOP_TEXTLINE2.

You get the content of the line with the property Text.

wnd[1]/usr/txtSPOP-TEXTLINE1.Text

But it is necessary to know the IDs or to detect it via GetObjectTree method.

Best regards
Stefan

Hello Schnell!

Thank you very much !

I also tried to display all the IDs under this WND[1]. They are as below:

1. id: wnd[1]/tbar[0]
   type: GuiToolbar
   Text = ""

2. id: wnd[1]/usr/subSUBSCREEN:SAPLSPO1:0502/cntlHTML_CONTROL_CON/shellcont/shell
   Type: GuiShell
   SubType: HTMLViewer
   Text: "SAP.HTMLControl.1"

3. id: wnd[1]/usr/txtICON_POPUP_TYPE
   Type: GuiTextField
   Text: ""

4. id: wnd[1]/usr/btnBUTTON_1
   ToolTip: "Yes"
   IconName: ""

5. id: wnd[1]/usr/btnBUTTON_2
   ToolTip: "No"
   IconName: ""

I believe that the TEXT I need to get are in the #2, it is NOT a GuiTextField. The TEXT seems to be written in the HTMLViewer.

Just before update the SapGui version 7.70, we had used the version 7.40. When we had used the SapGui Verion 7.40, I got the text like below

t = session.findById(id).BrowserHandle.document.all(0).innerText

However, with SapGui Version 7.70, a ERROR comes like "BrowserHandel is [NonObject]".

Could you please tell me any method or idea or anything about how to get the TEXT from HTMLViewer of SapGui Version 7.70?

Stefan-Schnell
Active Contributor

anh_masa

Hello Masa,

the current SAP GUI for Windows offers the possibility to switch between different browser controls.

If I choose Internet Explorer the following code works well and as expected.

'-Call TAC SE38---------------------------------------------------------
session.findById("wnd[0]/tbar[0]/okcd").text = "/nse38"
session.findById("wnd[0]").sendVKey 0

'-Execute report SAPHTML_DEMO1------------------------------------------
session.findById("wnd[0]/usr/ctxtRS38M-PROGRAMM").text = "SAPHTML_DEMO1"
session.findById("wnd[0]/tbar[1]/btn[8]").press

WScript.Sleep(5000)

'-Get the handle of the InternetExplorer.Application object-------------
Set oBrowser = session.findById("wnd[0]/usr/cntlHTML/shellcont/shell").BrowserHandle

'-Get the innerText of the body tag of the HTML site--------------------
MsgBox oBrowser.document.body.innerText
MsgBox oBrowser.document.all(0).innerText

If I choose Edge I get an error.

Object or property document is not supported. I assume this is the same error as yours.

Interesting: When I call the script again, after this error, the SAP GUI for Windows is completely terminated.

It seems that Edge doesn't support the document object.

Now I tried the same with PowerShell to see the difference.

#-Call TAC SE38---------------------------------------------------------
$ID = Invoke-Method -object $session -methodName "findById" -methodParameter @("wnd[0]/tbar[0]/okcd");
Set-Property -object $ID -propertyName "text" -propertyValue @("/nSE38");
$ID = Invoke-Method -object $session -methodName "findById" -methodParameter @("wnd[0]");
Invoke-Method -object $ID -methodName "sendVKey" -methodParameter @(0);

#-Execute report SAPHTML_DEMO1------------------------------------------
$ID = Invoke-Method -object $session -methodName "findById" -methodParameter @("wnd[0]/usr/ctxtRS38M-PROGRAMM");
Set-Property -object $ID -propertyName "text" -propertyValue @("SAPHTML_DEMO1");
$ID = Invoke-Method -object $session -methodName "findById" -methodParameter @("wnd[0]/usr/ctxtRS38M-PROGRAMM");
Set-Property -object $ID -propertyName "caretPosition" -propertyValue @(13);
$ID = Invoke-Method -object $session -methodName "findById" -methodParameter @("wnd[0]");
Invoke-Method -object $ID -methodName "sendVKey" -methodParameter @(8);

#-Get the handle of the InternetExplorer.Application object-------------
$ID = Invoke-Method -object $session -methodName "findById" -methodParameter @("wnd[0]/usr/cntlHTML/shellcont/shell");
$oBrowser = Get-Property -object $ID -propertyName "BrowserHandle"

With the InternetExplorer object it delivers this:

Application          : System.__ComObject
Parent               : System.__ComObject
Container            : System.__ComObject
Document             : mshtml.HTMLDocumentClass
TopLevelContainer    : False
Type                 : HTML-Dokument
Left                 : 0
Top                  : 0
Width                : 943
Height               : 592
LocationName         : saphtmlp://htmlviewer.sap.com/00mfhTFj7joHklHUeWfWdG/HTML000001.HTM
LocationURL          : saphtmlp://htmlviewer.sap.com/00mfhTFj7joHklHUeWfWdG/HTML000001.HTM
Busy                 : False
Name                 : Microsoft-Browsersteuerelement
HWND                 : 
FullName             : C:\Program Files (x86)\SAP\FrontEnd\SAPgui\saplogon.exe
Path                 : C:\Program Files (x86)\SAP\FrontEnd\SAPgui\
Visible              : True
StatusBar            : True
StatusText           : 
ToolBar              : 1
MenuBar              : True
FullScreen           : False
ReadyState           : 4
Offline              : False
Silent               : False
RegisterAsBrowser    : False
RegisterAsDropTarget : True
TheaterMode          : False
AddressBar           : True
Resizable            : 

With the Edge object it delivers this ...

PostData              : System.__ComObject
URLPrefixLocal        : SAPHTMLP://htmlviewer.sap.com/00mfhTFj7joHkja78xJ0dG/
NavigationStyle       : 
TargetFrame           : 
URLPrefixGlobal       : saphtmlp://
UIFlag                : 0
DocumentComplete      : 1
Headers               : 
PostDataLength        : 0
URLLength             : 0
BrowserVersion        : 0
TryUseSAPHTMLP        : 0
BrowserString         : 
Version               : 
ScriptRecording       : 
PostDataModified      : 
SimpleBrowse          : 
EndSessionWithBrowser : 
ScriptText            : 
BrowserHandle         : 
ScriptOnABAPCompleted : 
ScriptOnDataSubmitted : 

... and the SAP GUI for Windows terminated abrupt.

It seems that Edge doesn't support this kind of access to the content of an HTML control.

What else is left but to switch to the InternetExplorer control?

Best regards
Stefan

0 Likes

Thank you very much !!

It is very much wonder why our SapGui version 7.70 could not get the TEXT from the BrowserHandel...

I checked OPTION of the SAP, it is set Internet Explorer.

and, this says that THE ONLY BROWSER CONTROL AVAILABLE.... means here always set as Internet Explorer.

I tried to get the TEXT again, however could not get the innertext.

   
    ID = "wnd[1]/usr/subSUBSCREEN:SAPLSPO1:0502/cntlHTML_CONTROL_CON/shellcont/shell"
    wnd1title = sapSession(0).findbyid("wnd[1]").Text
    idtext = sapSession(0).findbyid(ID).Text
    childrencount = sapSession(0).findbyid(ID).Children.Count
    
    On Error Resume Next
    inner_text = "XX"
    inner_text = sapSession(0).findbyid(ID).BrowserHandle.document.all(0).innerText
        
    Debug.Print "wnd1Title: " & wnd1title
    Debug.Print "idText: " & idtext
    Debug.Print "childrenCount: " & childrencount
    Debug.Print "innerText: " & inner_text
    Debug.Print "errNo: " & Err.Number


My Results:
wnd1Title: Information
idText: SAP.HTMLControl.1
childrenCount: 0
innerText: XX
errNo: 91

Do you think that I could not get the InnerText because of our SapGui Version?

Stefan-Schnell
Active Contributor
0 Likes

anh_masa

Now I tried it with the same popup windows as yours with the following script:

'-Call TAC SE37---------------------------------------------------------
session.findById("wnd[0]/tbar[0]/okcd").text = "/nSE37"
session.findById("wnd[0]").sendVKey 0

'-Call FM POPUP_TO_CONFIRM----------------------------------------------
session.findById("wnd[0]/usr/ctxtRS38L-NAME").text = "POPUP_TO_CONFIRM"
session.findById("wnd[0]").sendVKey 8

'-Fill the arguments----------------------------------------------------
session.findById("wnd[0]/usr/txt[34,7]").text = "Information"
session.findById("wnd[0]/usr/txt[34,9]").text = "This is a test"
session.findById("wnd[0]/usr/txt[34,10]").text = "Yes"
session.findById("wnd[0]/usr/txt[34,12]").text = "No"
session.findById("wnd[0]/usr/txt[34,15]").text = ""
session.findById("wnd[0]").sendVKey 8

WScript.Sleep(2500)

'-Get the handle of the InternetExplorer.Application object-------------
ID = "wnd[1]/usr/subSUBSCREEN:SAPLSPO1:0502/cntlHTML_CONTROL_CON/shellcont/shell"
Set oBrowser = session.findById(ID).BrowserHandle

'-Get the innerText of the body tag of the HTML site--------------------
MsgBox oBrowser.document.body.innerText

'-Get the innerText-----------------------------------------------------
inner_text = session.findbyid(ID).BrowserHandle.document.all(0).innerText
MsgBox inner_text

It works without any problems.

I use PL 4.

The error number 91 tells us that you attempted to use an object property without a valid object.

Try the following code to detect which object doesn't exists:

ID = "wnd[1]/usr/subSUBSCREEN:SAPLSPO1:0502/cntlHTML_CONTROL_CON/shellcont/shell"
Set oBrowser = session.findById(ID).BrowserHandle
On Error Resume Next
If IsObject(oBrowser) Then
  MsgBox "Browser object exists"
  Set oDocument = oBrowser.document
  If IsObject(oDocument) Then
    MsgBox "Document object exists"
  Else
    MsgBox "No document object exists"
  End If
Else
  MsgBox "No browser object exists"
End If
0 Likes

Thank you very much for keeping help me !!

I tried your code, and found the Browser Object is exists - and found the No Document Object.

I also tried to catch the Error by Python, the results are follow, it says [NoneTyep] object has no attribute "Document". Does this mean the Browser object exists, but it is noneType = EMPTY ??

This problem comes from Patch Level... ?? Our system using the PL = 1, not the latest as same as PL=4 of yours...

id = "wnd[1]/usr/subSUBSCREEN:SAPLSPO1:0502/cntlHTML_CONTROL_CON/shellcont/shell"
print("Text:", session.findbyid(id).text)
print("Type:", session.findbyid(id).type)
print("SubType:", session.findbyid(id).Subtype)
print("InnerText:", session.findByID(id).BrowserHandle.document.all(0).innerText())

*** Results  ***
Text: SAP.HTMLControl.1
Type: GuiShell
SubType: HTMLViewer

**** ERROR  ****
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-5-d7695c309119> in <module>
      3 print("Type:", session.findbyid(id).type)
      4 print("SubType:", session.findbyid(id).Subtype)
----> 5 print("InnerText:", session.findByID(id).BrowserHandle.document.all(0).innerText())

AttributeError: 'NoneType' object has no attribute 'document'
Sandra_Rossi
Active Contributor
0 Likes

anh_masa You can at least install PL 4 to see if it works. If yes, probably it will be the only solution for you (to work with or wait for PL 4 to be installed in your company), SAP can't backport a fix to PL 1. But you can ask SAP support which exact PL fixed the issue.

Hello Schnell,

Thank you very much helping me long time!

Because of you sent the picture of the Sap Version - and you said about the Patch Level, so Now I understand reason why our SapGui (PL-1) could not reply anything from the BrowserHandle. I have to wait for Patch Level 3.

Thank you again!

Best regards,

Masa