- ramsen
- Posts : 5
Join date : 2011-01-19
Grabbing the current URL and storing it as a string.
Wed Jan 19, 2011 5:55 am
I'd like to store the URL of the page I'm on as a string. I tried using window.location.href to grab the URL from the current window, but since the current open window is Selenium IDE and not the web page it does not work. Is there another way I can take the URL and store it using javascript or Selenium commands?
I want to be able to check the URL and change certain variables based on the URL.
I want to be able to check the URL and change certain variables based on the URL.
- ramsen
- Posts : 5
Join date : 2011-01-19
Re: Grabbing the current URL and storing it as a string.
Wed Jan 19, 2011 8:18 am
I actually figured out how to grab the URL, but I'm still stumped on how to parse the string.
I used the command:
storeLocation | site | |
Now I would like to get the data in "site" and parse it as a string.
I used the command:
storeLocation | site | |
Now I would like to get the data in "site" and parse it as a string.
- PriyankaRegular Participant
- Posts : 27
Join date : 2010-10-04
Re: Grabbing the current URL and storing it as a string.
Wed Jan 19, 2011 7:09 pm
Pls try this
string site = selenium.GetLocation();
string[] location = site.Split('/');
for(int i = 0; i < location.length; i++)
{
Console.WriteLine(location[i]);
}
string site = selenium.GetLocation();
string[] location = site.Split('/');
for(int i = 0; i < location.length; i++)
{
Console.WriteLine(location[i]);
}
- ramsen
- Posts : 5
Join date : 2011-01-19
Re: Grabbing the current URL and storing it as a string.
Thu Jan 20, 2011 5:47 am
I'm actually close to getting this to work, but now I hit an exception every time.
[error] Threw an exception: missing ; before statement
I have only two commands.
1. storeLocation | site | |
2. storeEval | js code below | n |
If I change my array to contain integers instead of strings the code works. Why would using strings cause an error?
For example; if I change var n = ["Is Google" , "Not Google"]; to var n = [100 , 200]; the code works perfectly.
Thanks for the help.
[error] Threw an exception: missing ; before statement
I have only two commands.
1. storeLocation | site | |
2. storeEval | js code below | n |
- Code:
javascript{
var n = ["Is Google" , "Not Google"];
if(storedVars['site'] == "http://www.google.com/")
{
n[0];
}
else
{
n[1];
}
}
If I change my array to contain integers instead of strings the code works. Why would using strings cause an error?
For example; if I change var n = ["Is Google" , "Not Google"]; to var n = [100 , 200]; the code works perfectly.
Thanks for the help.
Permissions in this forum:
You cannot reply to topics in this forum