My page URL is mentioned below, I want to get JID
value.
http://.........../abc.aspx?JID=00001833
I can get complete URL from this code, but I want to get specific value.
string url = driver.Url;
Console.WriteLine(url);
My page URL is mentioned below, I want to get JID
value.
http://.........../abc.aspx?JID=00001833
I can get complete URL from this code, but I want to get specific value.
string url = driver.Url;
Console.WriteLine(url);
UPDATE:
As JeffC suggested the proper way to get parameters you should use HttpUtility.ParseQueryString
String yoururl = "http://example.com/abc.aspx?JID=00001833";
Uri theUri = new Uri(yoururl);
String jid = HttpUtility.ParseQueryString(theUri.Query).Get("JID");
Console.WriteLine(jid);
Read more about ParseQueryString
here: https://msdn.microsoft.com/en-us/library/ms150046.aspx
*Not recommended way (with string manipulation):
If your jid's length is fix you can do the following:*
string url = driver.Url;
string jid = url.Substring(url.Length-8,8)
Console.WriteLine(jid);
Your example redone
string url = driver.Url;
string newUrl = url.Split('=').Last();
Console.WriteLine(newUrl);
Try this using string.Split
DotNetFiddle Example You can run
Here is the code from within the fiddle:
var URL = "http://.........../abc.aspx?JID=00001833";
var JID = URL.Split('?').Last();
Console.WriteLine(JID);
var JIDVal = JID.Split('=').Last();
Console.WriteLine(JIDVal);