Hi,
I am trying to extract a variable from the URL itself and set it as a string. What I tried to do is the following.
sample code:
string URL = ActiveBrowser.Url.ToString();
string Variable= (URL).SubString(84, 2);
NativeWindow window = new NativeWindow();
window.AssignHandle(ActiveBrowser.Window.Handle);
MessageBox.Show(URL);
I am getting a compilation failure, what is the correct way of setting the URL as a string, trimming it as needed and setting it as a variable(int).
I am trying to extract a variable from the URL itself and set it as a string. What I tried to do is the following.
sample code:
string URL = ActiveBrowser.Url.ToString();
string Variable= (URL).SubString(84, 2);
NativeWindow window = new NativeWindow();
window.AssignHandle(ActiveBrowser.Window.Handle);
MessageBox.Show(URL);
I am getting a compilation failure, what is the correct way of setting the URL as a string, trimming it as needed and setting it as a variable(int).
4 Answers, 1 is accepted
0
Hello Dan,
here's how to get your code to compile:
http://screencast.com/t/LT8Z77u7yK
It seems you haven't added an assembly reference to System.Windows.Forms as described at the beginning of this article:
http://www.telerik.com/automated-testing-tools/support/documentation/user-guide/code-samples/general/add-messagebox.aspx
Also, you don't need brackets in this line:
Also, you're not using Variable in the code - you can even remove that line entirely.
Also, you don't need to convert ActiveBrowser.URL to a String - it's a string by default. So the first line of your code can be just this:
Here's the revised code:
Kind regards,
Stoich
the Telerik team
here's how to get your code to compile:
http://screencast.com/t/LT8Z77u7yK
It seems you haven't added an assembly reference to System.Windows.Forms as described at the beginning of this article:
http://www.telerik.com/automated-testing-tools/support/documentation/user-guide/code-samples/general/add-messagebox.aspx
Also, you don't need brackets in this line:
string Variable= (URL).SubString(84, 2);
Also, you're not using Variable in the code - you can even remove that line entirely.
Also, you don't need to convert ActiveBrowser.URL to a String - it's a string by default. So the first line of your code can be just this:
string URL = ActiveBrowser.Url;
Here's the revised code:
string
URL = ActiveBrowser.Url;
NativeWindow window =
new
NativeWindow();
window.AssignHandle(ActiveBrowser.Window.Handle);
MessageBox.Show(URL);
Kind regards,
Stoich
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
Test Studio Trainings
0
Dan
Top achievements
Rank 1
answered on 24 Aug 2012, 07:16 PM
Hi,
I do need the variable because I need to plug it in a query later to do a SQL validation.
Also I do have Systems.Windows.Forms, what I need to know is how to trim URL down to the only part that is needed.
my revised code looks like this:
string URL = ActiveBrowser.Url;
string DigitalInstanceID = URL.Substring(80,3);
NativeWindow window = new NativeWindow();
window.AssignHandle(ActiveBrowser.Window.Handle);
MessageBox.Show(DigitalInstanceID);
it does compiles now but I get a blank messagebox.
I do need the variable because I need to plug it in a query later to do a SQL validation.
Also I do have Systems.Windows.Forms, what I need to know is how to trim URL down to the only part that is needed.
my revised code looks like this:
string URL = ActiveBrowser.Url;
string DigitalInstanceID = URL.Substring(80,3);
NativeWindow window = new NativeWindow();
window.AssignHandle(ActiveBrowser.Window.Handle);
MessageBox.Show(DigitalInstanceID);
it does compiles now but I get a blank messagebox.
0
Hello Dan,
what would be a typical URL that you're working with and how would you like to trim it? Which part of it would you like to leave out? Give me these details so that I may assist you with putting together the solution.
You're currently use the following line to trim the URL:
This code translates as:
"From the URL string: get the character indexed at 80 as well as the next 3 characters"
So invoking this operation on the following URL:
would return the following:
I would recommend that you use a different approach to trimming the URL. Gimme the details so that I may assist.
I'm not sure why the alert box would come up empty. What you should try is to output the string you're getting to the Log so that you may examine it and verify it's not emtpy:
This line will write it the the Log and you can review it after the test run (screenshot 1).
All the best,
Stoich
the Telerik team
what would be a typical URL that you're working with and how would you like to trim it? Which part of it would you like to leave out? Give me these details so that I may assist you with putting together the solution.
You're currently use the following line to trim the URL:
string
DigitalInstanceID = URL.Substring(80,3);
This code translates as:
"From the URL string: get the character indexed at 80 as well as the next 3 characters"
So invoking this operation on the following URL:
https://www.google.bg/#hl=bg&safe=active&sclient=psy-ab&q=abc&oq=abc&gs_l=hp.3..0l4.1061.4519.0.4634.12.9.1.0.0.0.190.1092.5j4.9.0...0.0...1c.plzykhcQIrc&pbx=1&bav=on.2,or.r_gc.r_pw.r_qf.&fp=5db6adbb8614535f&biw=1344&bih=711'
0l4
I would recommend that you use a different approach to trimming the URL. Gimme the details so that I may assist.
I'm not sure why the alert box would come up empty. What you should try is to output the string you're getting to the Log so that you may examine it and verify it's not emtpy:
Log.WriteLine(DigitalInstanceID);
This line will write it the the Log and you can review it after the test run (screenshot 1).
All the best,
Stoich
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
Test Studio Trainings
0
Dan
Top achievements
Rank 1
answered on 30 Aug 2012, 08:24 PM
Hi Stoich,
I was able to figure out how to extract it using URL.Substring(), thanks for your help!
I was able to figure out how to extract it using URL.Substring(), thanks for your help!