3

I want to retrieve the request parameters of the URL using selenum-1 Is there a way? I saw the API list getLocation() method returns the absolute URL.

If the URL is http://webserver/webapps/library/do/javabooks/author?author_id=42&book_id=55

If I am writting selenium.getLocation() it returns me http://webserver/webapps/library/do/javabooks/author. But I am interested in the request parameters. Or if I can get the full URL with request parameters using Selenium API that is also fine. Is there any way?

Thanks in advance.

1
  • if you were using webdriver I would say do driver.Url and that will capture the url in the address bar Commented Nov 17, 2011 at 15:04

1 Answer 1

3

I don't know of any function that does that... it is possible to verify the URL like you said, but for things that are just slightly different I tend to use Javascript:

selenium.get_eval('window.location.href');

If you need it often you might consider wrapping it in a library or function, but this seems quite clean to me. You could expand the Javascript a little to get more control over the returned data: splitting on the ? character and take only the second item in the array, for example. From that point on, perhaps split again on & to get the parameters returned as a list of strings?

Sign up to request clarification or add additional context in comments.

6 Comments

Thank you @jro : well through javaScript I already did, wanted to know if is there any direct way using Selelium API.
@java_enthu: not that I know of. I walked through the API reference again, but couldn't find anything that does work exactly to you expectations.
thank you. But with this I am finding an issue. The URL displayed in the webpage is webserver/webapps/library/do/javabooks/… but when I am doing selenium.getEval("window.location.href") it returns me webserver/webapps/library/do/javabooks/… And to my surprise both the URL show the same things on the page. But according to current requirement I would like to retrieve the former URL. I tried with window.location , window.location.href, document.location.href and document.location all return me the same URL.
That's odd... so is there a difference between the location you see in the address bar when running the tests and the one you get via Javascript? And is that url different from the one Selenium returns with its getLocation method?
@jro: That's exactly what selenium.getLocation does - it returns window.location.href.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.