# Can URI retrieve the URL of a webpage when its open?

**URL:** <https://www.ruby-forum.com/t/can-uri-retrieve-the-url-of-a-webpage-when-its-open/173591>\
**Category:** Ruby\
**Created:** [August 11, 2009, 8:00pm UTC](https://www.ruby-forum.com/t/can-uri-retrieve-the-url-of-a-webpage-when-its-open/173591 "2009-08-11T20:00:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![arti\_singh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ba9def/32.png) [@arti\_singh](https://www.ruby-forum.com/u/arti_singh)\
**Post date:** [August 11, 2009, 8:00pm UTC](https://www.ruby-forum.com/t/can-uri-retrieve-the-url-of-a-webpage-when-its-open/173591/1 "2009-08-11T20:00:52Z")

</div>

Can I use uri to get the URL Of a web page?  
I am opening a webapge by clicking on a link and I am flipping to this  
new window after I have gotten the handle, I attach to the window after  
attaching to this window, I want to use rio to save the webpage to a  
file since I need to check it. I can not depend on having a static URL  
since the system under test generates URLs dynamically

1 $ms=Watir::IE.attach(:title, htmlemailname)  
2 rio($ms)\>rio(“C://TestResult//index.html”)

Line 2 fails cause I think that rio wants

rio(“[www.webpage.com](http://www.webpage.com)”)\>rio(“C://TestResult//index.html”)

Is there any way to get the URL of a webpage once it is opened?

---

<div class="post-metadata">

**Author:** ![arti\_singh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ba9def/32.png) [@arti\_singh](https://www.ruby-forum.com/u/arti_singh)\
**Post date:** [August 12, 2009, 9:56am UTC](https://www.ruby-forum.com/t/can-uri-retrieve-the-url-of-a-webpage-when-its-open/173591/2 "2009-08-12T09:56:29Z")

</div>

> Is there any way to get the URL of a webpage once it is opened?

require ‘watir’  
w = Watir::IE.new  
u = ‘[http://somesitewithredirection.com](http://somesitewithredirection.com)’  
w.goto(u)

puts w.document.URL

---

<div class="post-metadata">

**Author:** ![arti\_singh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ba9def/32.png) [@arti\_singh](https://www.ruby-forum.com/u/arti_singh)\
**Post date:** [August 12, 2009, 4:47pm UTC](https://www.ruby-forum.com/t/can-uri-retrieve-the-url-of-a-webpage-when-its-open/173591/3 "2009-08-12T16:47:28Z")

</div>

\_\_ \_\_ wrote:

> > Is there any way to get the URL of a webpage once it is opened?
> 
> require ‘watir’  
> w = Watir::IE.new  
> u = ‘[http://somesitewithredirection.com](http://somesitewithredirection.com)’  
> w.goto(u)
> 
> puts w.document.URL

This bit won’t work since I dont know the URL,its dynamic. I am  
attaching to the window because I know the title and then I get the  
window handle and I interact with the window. but you have given me an  
idea cause I can get the URL after I have the handle.

Thanks!!!  
Arti
