0

I keep getting this error when the program is trying to output a file.

public void AccTest()
    {
        Console.WriteLine("AccTest started for small test");
        string title = chromeDriver.Title;
        string url = chromeDriver.Url;
        Console.WriteLine(title + " :: " + url);

        AxeResult axeResult = new AxeBuilder(chromeDriver).WithTags("wcag2a", "wcag2aa").Analyze();
        //Creates the Chrome HTML report and sends it the reports folder
        Directory.CreateDirectory(Application.StartupPath + "\\Reports");
        string path = Path.Combine(Application.StartupPath + "\\Reports", url + "-AccReport.html");
        chromeDriver.CreateAxeHtmlReport(axeResult, path);
        Console.WriteLine("Report Printed");

    }

The file will happily output the url to the console but won't put it onto the Path.Combine. is there a way to get to output?

  • What are you trying to do? Why are you combining paths with `+` and then use `Path.Combine` to even mix this up with a url? The third line form the bottom doesn't make any sense. If it worked you'd end up with a path like `(startuppath)\Reports\http://url-accreport.html`, what should that be? – René Vogt Sep 07 '20 at 11:36
  • So maybe you wanted to create a file or directory with a part of the url, but that had to be a relative path, not the complete url. – René Vogt Sep 07 '20 at 11:39
  • basically there is a list of urls put into a list box from a text file which the program will then take and run some tests on the site which output into a HTML file, as there are multiple site i wanted it to output multiple reports as if i have it so with a generic file name like "accreport.html" it will overwrite the file everytime. what i was trying to do was make it so that it took the URL from the site it is testing and added that to the filename. if that makes sense? – ShadowsFall88 Sep 07 '20 at 13:13
  • And it seems I was wrong, `Path.Combine` indeed let's you combine `"C:\\somedir"` with `"http://www.google.com/somequery"` into `"C:\\seomdir\http://www.google.com/somequery"`. But I'm sure `CreateAxeHtmlReport` will not be able to create a file with that weird name (paths containing `:` etc). If you [debug](https://stackoverflow.com/questions/25385173/what-is-a-debugger-and-how-can-it-help-me-diagnose-problems) your code you will see that `path` contains an invalid file name. You need to find a better algorithm to generate a valid path. – René Vogt Sep 07 '20 at 13:41
  • When you construct your path string you should remove every character from you string which is listed in `Path.GetInvalidPathChars()` and `Path.GetInvalidFileNameChars()`. – ckuri Sep 07 '20 at 16:34

0 Answers0