Find Browser URL on run-time

Hello,
It is possible to find the URL from a browser present on the screen, using a UiPath.Core.Browser object ?
Thanks

5 Likes

I’m not sure whether you can do it using the browser object, this is usually somewhere you would store the URL. I’d be going down the route of this

[http://windowsitpro.com/powershell/retrieve-information-open-browsing-sessions](http://windowsitpro.com/powershell/retrieve-information-open-browsing-sessions)

or this

I tried using inject js activity (which i’m experimenting laterly) and I was able to get the URL value.

Don’t use selector for inject js.

function(e) {
    return window.location.href;
}

browserUrl.zip (2.1 KB)

10 Likes

Nice one @vvaidya, I didn’t even know Inject JS existed. Amazing! :smiley:

2 Likes

The simple way is to use use GetAttribute with “url”. It works for browsers variables as well. Main.xaml (5.2 KB)

9 Likes

Thanks @Lavinia. This is a better solution, but when I run with browser variable(without selector) I get below error, do I need to modify anything?

Hey @vvaidya

You should just use the browser output variable and assign it to the “Get Attribute” Activity’s “element” property then it will work.

For more Reference, see the attached workflow and let me know :slight_smile:

*SideNote - Should use @Lavinia solutions because java script will be enabled in browsers or not depends on browser’s setting and some peoples because of security make java script disable, have faced such challenges like this.

GetBrowserURL_with_Get_Attrib.xaml (7.2 KB)

Regards…!!
Aksh

3 Likes

@aksh1yadav I tried to keep a delay and it seems to be working, now I’m trying to get the URL value by transitioning between multiple domain names.

Without delay also that was working fine. i have put delay because due to slow internet that page was taking time so it was returning default value “about:blank”.

Regards…!!
Aksh

@aksh1yadav Attached code should return 2 different Url’s, I think I’m missing some thing with variable1, can you check.

microsoft.com
live.com

browserurl-attribute.xaml (10.0 KB)

browserurl-attribute.xaml (9.5 KB)

Regards…!!
Aksh

I see you used Navigate URL for the transition can’t we achieve with Button click?

User asked he wanted to see what ever is on the screen.

In this context, user opnes microsoft.com > clicks on sign in > goes to live.com> after successful auth comes back to microsoft.com

With all it will work. You have to maintain the delay here because you are getting things from browser and its properties so if you will fire the get-attribute with url before the loading of next state it will return either the previous one (when you are switching from one state to other) otherwise default like “about:blank”.

check with sign in click sample: browserurl-attribute_with_click_sample.xaml (10.7 KB)

Regards…!!
Aksh

gave 10 second delay in your code.

I will check later. Thanks.

Regards…!!
Aksh

Lol…12 second delay worked. Thanks for the help man!

There is something like UiPath.Core.Activities.SetAttribute ?
Es: define isDraft for SendOutlookMail or visible for ExcelApplication Scope on run time based on a variable ( the alternative is to use IF and duplicate the activity in then / else ).
Thanks

There is, but it works with a Target object, so only for UI Automation activities.
The examples that you mentioned are a different story. Those properties are of type bool, so you can’t modify their values at runtime. In order to modify a property at runtime by setting a variable to it they need to be Argument. Currently though this cannot be modified.

Thanks,
Lavinia