Best way to validate URL in browser address bar?

Ask general questions here.
Fergal
Certified Professional
Certified Professional
Posts: 298
Joined: Tue Feb 18, 2014 2:14 pm
Location: Co Louth, Ireland
Contact:

Best way to validate URL in browser address bar?

Post by Fergal » Fri May 22, 2015 11:14 am

[Ranorex 5.2.2, Windows 7, testing website on Google Chrome.]

The test step below validates that a given URL is displayed in the Browser address bar.

Image


The XPath for the AddressAndSearchBar repository item looks like this:
/form[@title~'^{REMOVED}']/container/container[@accessiblerole='Client' and @accessiblehelp='BrowserView']/container[@accessiblerole='Client' and @accessiblehelp='TopContainerView']/toolbar[@accessiblename='main']/container[@accessiblerole='Grouping' and @accessiblehelp='LocationBarView']/text[@accessiblename='Address and search bar']
My issue is that the repository item above is not always found when the test runs. Is there an easier, simpler or standard way to validate that a particular URL, is the one displayed in the browser address bar?

Thanks!

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3949
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Best way to validate URL in browser address bar?

Post by odklizec » Fri May 22, 2015 12:22 pm

Hi,

I would suggest to use the PageUrl attribute of DOM element. And maybe it would be a good idea to add
WaitForDocumentLoaded() action before accessing the DOM element? You see, some attributes may not be filled until the page is not fully loaded.
PageUrl.png
PageUrl.png (6.9 KiB) Viewed 2436 times
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

Fergal
Certified Professional
Certified Professional
Posts: 298
Joined: Tue Feb 18, 2014 2:14 pm
Location: Co Louth, Ireland
Contact:

Re: Best way to validate URL in browser address bar?

Post by Fergal » Tue May 26, 2015 9:37 am

Thanks Pavel, that looks great and I will try using it.

rastek
Posts: 157
Joined: Wed Aug 06, 2014 12:00 pm

Re: Best way to validate URL in browser address bar?

Post by rastek » Mon Jun 29, 2015 12:55 pm

Hi odklizec,

I have two questions for your answer for this post

I am using Text attribute to get url, using PageUrl has more advantage ?

My second question is;

When I insert InvokeAction in Ranorex I only see EnsureVisible and Focus method, I can not see WaitFotDocumentLoaded ??

Thanks,
Rastek

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3949
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Best way to validate URL in browser address bar?

Post by odklizec » Mon Jun 29, 2015 1:06 pm

Hi,

As far as I know, there is no Text attribute available for DOM element? This is why you have to use PageUrl.

And you don't see WaitFotDocumentLoaded because you most probably not inserted DOM element to action table? WaitFotDocumentLoaded is only available for DOM element.
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

rastek
Posts: 157
Joined: Wed Aug 06, 2014 12:00 pm

Re: Best way to validate URL in browser address bar?

Post by rastek » Tue Jun 30, 2015 8:30 am

I am not getting Text for a DOM element, what I am saying is that, I can get Url from the object below using Text property

container[@accessiblename='Google Chrome']//toolbar[@accessiblename='main']/?/?/text[@accessiblename='Address and search bar']

So How will I add DOM element to action table ? And what is the point here ? Accessing objects without repository as in the case Descriptive Programming ?

Thanks,
Rastek.
Last edited by rastek on Tue Jun 30, 2015 1:49 pm, edited 1 time in total.

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3949
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Best way to validate URL in browser address bar?

Post by odklizec » Tue Jun 30, 2015 10:26 am

Hi,

In my opinion, validating url from the address bar is much less reliable than using PegeUrl attribute of DOM element, not to mention that the xpath of address bar may vary between browsers? You asked for best way of validating actual page url, so I suggested doing it via PageUrl attribute :)
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

rastek
Posts: 157
Joined: Wed Aug 06, 2014 12:00 pm

Re: Best way to validate URL in browser address bar?

Post by rastek » Tue Jun 30, 2015 1:51 pm

Hi odklizec
Thanks for the reply, and it will be fine if you can also reply to my second question, How will I add DOM element to action table ? and where is that action table actually ?

Thanks,
Rastek.

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3949
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Best way to validate URL in browser address bar?

Post by odklizec » Tue Jun 30, 2015 4:06 pm

Hi,

DOM is a top level element of each web page displayed in browser. If you start recording and click an element on page, its root level element should be DOM (automatically added to repository along with selected element).
DOM.png
DOM.png (117.31 KiB) Viewed 2324 times
By "actions table" I mean the table in Recording module, where you can find and edit all recorded or manually added actions...
http://www.ranorex.com/support/user-gui ... tions.html
Hope this helps? ;)
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

rastek
Posts: 157
Joined: Wed Aug 06, 2014 12:00 pm

Re: Best way to validate URL in browser address bar?

Post by rastek » Wed Jul 01, 2015 12:15 pm

Thanks but I still can not add WaitForDocumentLoaded there is no option when I add InvokeAction, how do you do that ?

Thanks,
Rastek

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3949
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Best way to validate URL in browser address bar?

Post by odklizec » Wed Jul 01, 2015 2:18 pm

Hi,

If you don't see WaitForDocumentLoaded in the InvokeAction, then you most probably don't access DOM element? WaitForDocumentLoaded is only available for DOM elements. But if you can access PageUrl and, for the same element, you don't see WaitForDocumentLoaded, that's definitely weird ;)

Anyway, I think you can easily try your test without WaitForDocumentLoaded. Just try to validate PageUrl.
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

rastek
Posts: 157
Joined: Wed Aug 06, 2014 12:00 pm

Re: Best way to validate URL in browser address bar?

Post by rastek » Thu Jul 02, 2015 9:05 am

I still can not understand something here, you write

then you most probably don't access DOM element? WaitForDocumentLoaded is only available for DOM elements.

How will access Dom element ? I just record , you do something different ? How you work with DOM element I do not ??

I record and my root element is /dom, but I can not see that Invoke Action and I wonder why..

I want to use WaitForDocumentLoaded in order to wait wap page fullt loaded, dont you also use it for that ?

Thanks.

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3949
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Best way to validate URL in browser address bar?

Post by odklizec » Thu Jul 02, 2015 9:31 am

Hi,

You need to Drag&Drop DOM element to recording table and then you should be able to access WaitForDocumentLoaded from InvokeAction menu...
DragDropDom.png
DragDropDom.png (37.48 KiB) Viewed 2273 times
InvokeActions cannot be recorded, they are only accessible after drag&drop of repo element to recording table and the list of accessible InvokeAction commands depends of repo element. Not all elements have the same actions. As mentioned before, WaitForDocumentLoaded is only available for DOM element. Hope this helps?
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

CookieMonster
Certified Professional
Certified Professional
Posts: 74
Joined: Mon Aug 14, 2006 7:17 pm
Location: CH

Re: Best way to validate URL in browser address bar?

Post by CookieMonster » Thu Jul 02, 2015 9:39 am

Hi Rastek,

If you want to wait, until the web page is loaded, then you have to create an function in the user code and use the Ranorex API, it is the easiest way.

The Repository Item has to be a dom object.

Here an example how you can implement it.

Code: Select all

public void WaitTilMyPageIsLoaded(RepoItemInfo myDomRepoInfo)
{
      WebDocument webDocument = (WebDocument) myDomRepoInfo.CreateAdapter<Unknown>(true).Element;

      while(webDocument.State != "complete")
      {
         webDocument.WaitForDocumentLoaded()
      }

}
But keep in mind, if your webpage uses a lot of of Ajax, then this way is not going to work.


Cheers
Dan

CookieMonster
Certified Professional
Certified Professional
Posts: 74
Joined: Mon Aug 14, 2006 7:17 pm
Location: CH

Re: Best way to validate URL in browser address bar?

Post by CookieMonster » Thu Jul 02, 2015 9:48 am

Hi Pavel,

Cool, now I have learned something. Because I seldom drag and drop the repository item first, especial a DOM object, hence I have never seen this actions.

Regards
Dan