StrokesPlus.net
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
beast0815  
#1 Posted : Friday, July 19, 2024 12:54:26 PM(UTC)
beast0815

Rank: Newbie

Reputation:

Groups: Approved
Joined: 7/19/2024(UTC)
Posts: 4
Germany

Thanks: 1 times
Was thanked: 1 time(s) in 1 post(s)
Hi,

I'm looking for a function to fetch the URL from a browser window / tab, where the gesture was drawn.
Depending on that URL, the action performed should be different. - So a specific website can have one gesture do other actions that the rest.

Background: We are introducing a new SAP ERP system in our company. Before, we used the SAP GUI, which is a installed prgram and you could easily create a app definition and have actions on that. New SAP is used via WebUI "Fiori" in the browser, so I'm not able to distinguish between a random website and the ERP system, unless I check on which URL the gesture is drawn.

I made up a solution, where I copy the URL from the address bar:

Initializing global variables in global load section. (Don't know if this is good style or just unnecessary...)

Code:
var g_isEdgeFiori = false;
var g_SAPLang = "";


Then grab the URL in the Edge browser before automation section and set the variables accordingly

Code:
sp.Sleep(10);
sp.SendModifiedVKeys([vk.LCONTROL],[vk.VK_L]);
sp.Sleep(80);
sp.SendModifiedVKeys([vk.LCONTROL],[vk.VK_C]);
sp.Sleep(10);
sp.SendVKey(vk.ESCAPE);
var l_URL = clip.GetText();
if (l_URL.includes(".sap.mycompanydomain.com:")) {
    g_isEdgeFiori = true
    if (l_URL.includes("sap-language=DE") || l_URL.includes("sap-language=de")) {
        g_SAPLang = "DE";
    } else {
        g_SAPLang = "EN";
    }
}
l_URL = "";


The action, for example navigate back, checks if it's Fiori (and if needed the language) and depending sends different keys

Code:
if (g_isEdgeFiori) {
    sp.SendVKey(vk.F3);
} else {
    sp.SendVKey(vk.BROWSER_BACK);
}


Finally resetting the global variables in after action automation

Code:
g_isEdgeFiori = false;
g_SAPLang = "";



This works ok, but it's not a elegant solution and it terribly spams the clipboard history (Windows 10 / 11 feature), that we heavily use.

I would need a reliable solution, that doesn't use the clipboard.
Searched for similar approaches and found a AutoHotKey script, that does what I ask for: GetUrl
Tried to get behind how this works and build it in S+, but failed. - I'm not a developer, so my coding skills are pretty basic...

Calling the AHK script from S+ is not a good solution, since it should be standalone in S+, that I can forward this to co-workers without having to struggle setting up AHK along with it.

Using a separate browser for the Fiori vs. the regular websites is not possible. We are limited to Edge.

So the big questions are:
Does S+ have a implemented function to get the URL from the browser?
If not, is there a way to mimic the function of the AHK script above? - Looks like COM interfaces are used there. Can S+ do that, too?
Or is there any other way with the given parameters?

Thanks for some support here.

Best regards,
Michael
thanks 1 user thanked beast0815 for this useful post.
More on 8/1/2024(UTC)
Rob  
#2 Posted : Sunday, July 21, 2024 7:11:03 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,382
United States
Location: Tampa, FL

Thanks: 28 times
Was thanked: 430 time(s) in 363 post(s)
I was able to use this package to get the COM interop DLL out for UIAutomation:

https://www.nuget.org/packages/Interop.UIAutomationClient

Here is just the DLL, which you can install via S+ as a Plug-In:

https://www.strokesplus.net/files/plugins/Interop.UIAutomationClient.dll.zip

NOTE: I found an error in the S+ plugin loading code that was blowing up with this DLL, so please download the latest S+ version (0.5.7.9) first!

After that plug-in is loaded, this script (created by mimicking the AHK GetUrl method you linked) worked for me in a quick test against an Edge window:

Code:

try {
    var fgw = sp.ForegroundWindow();
    var winClass = fgw.ClassName;
    var cUIAutomation = new CUIAutomationClass();
    var rootElement = cUIAutomation.ElementFromHandle(fgw.HWnd); 
    var controlTypeId = winClass.includes("Chrome") ? UIA_ControlTypeIds.UIA_EditControlTypeId : UIA_ControlTypeIds.UIA_DocumentControlTypeId;
    var condition = cUIAutomation.CreatePropertyCondition(UIA_PropertyIds.UIA_ControlTypePropertyId, controlTypeId);
    var eFirst = rootElement.FindFirst(TreeScope.TreeScope_Descendants, condition);
    var url = eFirst.GetCurrentPropertyValue(UIA_PropertyIds.UIA_ValueValuePropertyId);
    StrokesPlus.Console.Log(url);
} catch(err) {
    StrokesPlus.Console.Log(`Get URL Error: ${err.message}`);
} finally {
   cUIAutomation = null;
   rootElement = null;
   eFirst = null;
   condition  = null;
}

Note that I reversed this ternary from what I feel the AHK script is doing, and after doing so, the URL was getting found:
Code:
var controlTypeId = winClass.includes("Chrome") ? UIA_ControlTypeIds.UIA_EditControlTypeId : UIA_ControlTypeIds.UIA_DocumentControlTypeId;

//Seems like it should be this, but swapping worked for me - so just FYI:
var controlTypeId = winClass.includes("Chrome") ? UIA_ControlTypeIds.UIA_DocumentControlTypeId : UIA_ControlTypeIds.UIA_EditControlTypeId;

Edited by user Monday, July 22, 2024 2:47:40 PM(UTC)  | Reason: Not specified

thanks 2 users thanked Rob for this useful post.
beast0815 on 7/25/2024(UTC), More on 8/1/2024(UTC)
beast0815  
#3 Posted : Thursday, July 25, 2024 10:39:13 AM(UTC)
beast0815

Rank: Newbie

Reputation:

Groups: Approved
Joined: 7/19/2024(UTC)
Posts: 4
Germany

Thanks: 1 times
Was thanked: 1 time(s) in 1 post(s)
Amazing!
Had it running for a couple of days now. Works perfectly.
Many thanks, Rob.
BigGrin

Now I just have to fiddle around with the correct hotkeys for the inputs. Unfortunately SAP didn't use them consistently in the Fiori WebUI... Mad

Edited by user Thursday, July 25, 2024 10:40:42 AM(UTC)  | Reason: Not specified

Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.