Selenium Forum: Functional And Regression Testing Tool.
Would you like to react to this message? Create an account in a few clicks or log in to continue.
Search
Display results as :
Advanced Search
Latest topics
AEM Training | Free Online DemoWed Apr 21, 2021 5:45 pmazharuddin
c# PageFactory - issue initializing elementsFri Nov 01, 2019 8:40 pmthegoatboy
Selenium making automatic connection to random urlsMon Jul 08, 2019 12:58 pmrepairtechsolutions1
How can we design the custom framework in Selenium RCMon Jun 24, 2019 2:26 pmrandybonnettes
What are the new features in Selenium 3.0Tue Jun 18, 2019 5:37 pmpappyvicky
What are you using Selenium for? Fri Apr 12, 2019 3:52 amzhl
LIMITATIONS OF SELENIUMWed Apr 10, 2019 11:23 amswara
Navigation
 Portal
 Index
 Memberlist
 Profile
 FAQ
 Search

Go down
avatar
ramsen
Posts : 5
Join date : 2011-01-19

Grabbing the current URL and storing it as a string.  Empty 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.
avatar
ramsen
Posts : 5
Join date : 2011-01-19

Grabbing the current URL and storing it as a string.  Empty 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.
avatar
Priyanka
Regular Participant
Regular Participant
Posts : 27
Join date : 2010-10-04

Grabbing the current URL and storing it as a string.  Empty 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]);
}
avatar
ramsen
Posts : 5
Join date : 2011-01-19

Grabbing the current URL and storing it as a string.  Empty 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 |

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.
Sponsored content

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

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