Search
 
 

Display results as :
 


Rechercher Advanced Search

Navigation
 Portal
 Index
 Memberlist
 Profile
 FAQ
 Search

Grabbing the current URL and storing it as a string.

View previous topic View next topic Go down

Grabbing the current URL and storing it as a string.

Post by ramsen on 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.

ramsen

Posts : 5
Join date : 2011-01-19

Back to top Go down

Re: Grabbing the current URL and storing it as a string.

Post by ramsen on 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.

ramsen

Posts : 5
Join date : 2011-01-19

Back to top Go down

Re: Grabbing the current URL and storing it as a string.

Post by Priyanka on 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]);
}

Priyanka
Regular Participant
Regular Participant

Posts : 27
Join date : 2010-10-04

Back to top Go down

Re: Grabbing the current URL and storing it as a string.

Post by ramsen on 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 |

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.

ramsen

Posts : 5
Join date : 2011-01-19

Back to top Go down

Re: Grabbing the current URL and storing it as a string.

Post by Sponsored content


Sponsored content


Back to top Go down

View previous topic View next topic Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum