0

I am trying to create a valid URL:

private string Urlpath { get; set; }
Driver.Navigate().GoToUrl(Urlpath);

    private void Button_URL(object sender, RoutedEventArgs e)
    {
        var dialog = new MyDialog();
        if (dialog.ShowDialog() == true)
        {
            MessageBox.Show("Refreshing a URL requires you to select a folder.");
            string Urlpath = dialog.ResponseText;
            Status_HTML.Content = "Selected:" + "\n" + Urlpath + "\n" + "Save and/or edit any file in your folder to get started!";
        }
    }

Urlpath is a string value from an input box like http://localhost/laravel/project/public/ but it says that its not a valid url. Actually it says System.ArgumentNullException: Argument 'url' cannot be null. because it probably only accept valid Urls but there's a string value. How can I turn this string into a URL?

Sen
  • 5
  • 3

1 Answers1

0

You have not assigned any value to the UrlPath property, Assign the required URL to UrlPath property and then use it to pass to the method.

Urlpath = "http://localhost/laravel/project/public/";
Driver.Navigate().GoToUrl(Urlpath);

EDIT You need to call Navigate after you have assigned UrlPath property from the dialog.ResponseText private string Urlpath { get; set; }

    private void Button_URL(object sender, RoutedEventArgs e)
    {
        var dialog = new MyDialog();
        if (dialog.ShowDialog() == true)
        {
            MessageBox.Show("Refreshing a URL requires you to select a folder.");
            string Urlpath = dialog.ResponseText;
            Status_HTML.Content = "Selected:" + "\n" + Urlpath + "\n" + "Save and/or edit any file in your folder to get started!";
            Driver.Navigate().GoToUrl(Urlpath);
        }
    }
Ipsit Gaur
  • 2,872
  • 1
  • 23
  • 38
  • This works but whenever I ask for input and the input would be http://localhost/laravel/project/public/ - it does not recognise it as a url – Sen May 29 '18 at 16:11
  • From where are you taking input, please paste the complete code of yours, also there need to be protocol i.e http or https to make a valid URL – Ipsit Gaur May 29 '18 at 16:13
  • I have edited my code, it shows the url in html_content but in a method it says that the get returned null – Sen May 29 '18 at 16:19
  • Can't I use it in another method? because I want to call the go to url in a file changed method – Sen May 29 '18 at 16:23
  • You can always call the method once the UrlPath is assigned the proper value – Ipsit Gaur May 29 '18 at 16:25
  • Looks like I had to remove string from Urlpath – Sen May 29 '18 at 16:32