【问题标题】:How to set a relative path in C# selenium for IE driver如何在 C# selenium 中为 IE 驱动程序设置相对路径
【发布时间】:2021-05-20 03:49:03
【问题描述】:

在下面的代码中,IEDriverServer.exe 在我的本地机器上可用。我想在不同的机器上运行这段代码。 C#获取IEDriverServer.exe时如何设置相对路径。

InternetExplorerOptions options = new InternetExplorerOptions()
            {
                ForceCreateProcessApi = true,
                BrowserCommandLineArguments = "-private",
                IntroduceInstabilityByIgnoringProtectedModeSettings = true,
                IgnoreZoomLevel = true
                
            };
            IWebDriver driver = new InternetExplorerDriver(Path.GetFullPath("C:\\Users\\kamal\\Documents\\Sample\\Sample\\bin\\Debug"), options);

            driver.Navigate().GoToUrl("https://www.google.com");

            driver.Quit();

【问题讨论】:

    标签: c# selenium-webdriver internet-explorer path relative-path


    【解决方案1】:

    如果文件的路径是 C:\Users\kamal\Documents\Sample\Sample\bin\Debug\IEDriverServer.exe

    相对路径是:

    driver = new InternetExplorerDriver(Path.GetFullPath(@"..\"), options); 
    

    如果它的 C:\Users\kamal\Documents\Sample\Sample\bin\Debug\netcoreapp3.1\IEDriverServer.exe

    你可以使用driver = new InternetExplorerDriver(".", options);

    更详细的路径如下:

    var projectRoot = Path.GetFullPath(@"..\..\..\"); //which in your case is C:\\Users\\kamal\\Documents\\Sample\\Sample\\
    var projectRootBin = Path.GetFullPath(@"..\..\"); // C:\\Users\\kamal\\Documents\\Sample\\Sample\\bin
    var projectRootBinDebug = Path.GetFullPath(@"..\"); // C:\\Users\\kamal\\Documents\\Sample\\Sample\\bin\Debug
    var projectRootBinDebugNetCoreApp31 = Path.GetFullPath("."); // C:\\Users\\kamal\\Documents\\Sample\\Sample\\bin\Debug\\netcoreapp3.1
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-02-15
      • 2016-04-29
      • 2021-05-26
      • 2015-03-03
      • 1970-01-01
      • 2018-07-12
      • 1970-01-01
      • 2021-07-07
      相关资源
      最近更新 更多