Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in DevOps and Agile by (19.7k points)

Is it possible to retrieve the value of the base URL from inside a Selenium script (a plain HTML-saved script from Selenium IDE)?

What I'm trying to do is verify the current URL using assertLocation. But assertLocation returns the absolute URL. I would like to compare the current URL to a relative URL without having to use an * at the start of the URL.

I'd like to have access to the base string because I want to be able to run the tests on different sites (various dev sites + production site), but if I use the * I can not check for the root page (*/ would be true for each page that ends with a /...)

This is what I currently do:

|assertLocation | */some-page | |

This is what I'd like to do:

|assertLocation | baseURL + "/some-page" | |

Note: is it even possible to:

use a variable in the target;

concatenate a variable and a string?

1 Answer

0 votes
by (62.9k points)

You can also open your base page and use storeLocation to put the current location into a variable. Use the below code:

|open|/||

|storeLocation|host||

|assertLocation|${host}somepage.html

By corresponding SSL URL.l|storeEval|window..toString().replace(new RegExp("^http://([^:]+):80"), "

https://$1:40");|hostSSL|

If you are interested to learn Selenium on a much deeper level and want to become a professional in the testing domain, check out Intellipaat’s Selenium certification

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94.1k users

Browse Categories

...