如何为IE驱动程序设置C#硒中的相对路径[英] How to set a relative path in C# selenium for IE driver

本文是小编为大家收集整理的关于如何为IE驱动程序设置C#硒中的相对路径的处理方法,想解了如何为IE驱动程序设置C#硒中的相对路径的问题怎么解决?如何为IE驱动程序设置C#硒中的相对路径问题的解决办法?如何为IE驱动程序设置C#硒中的相对路径问题的解决方案?那么可以参考本文帮助大家快速定位并解决问题,译文如有不准确的地方,大家可以切到English参考源文内容。

问题描述

在下面的代码中,我的本地计算机可用.我想在不同的机器中运行此代码.如何在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:\ users \ kamal \ documents \ sample \ sample \ sample \ bin \ debug \ debug \ iedriverserver.exe

相对路径是:

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

如果其c:\ users \ kamal \ documents \ sample \ sample \ bin \ bin \ debug \ 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

本文地址:https://www.itbaoku.cn/post/2352428.html

问题描述

In the below code, IEDriverServer.exe is available in my local machine. I want to run this code in different machines. How to set a relative path while getting IEDriverServer.exe in C#.

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();

推荐答案

If the path to the file is C:\Users\kamal\Documents\Sample\Sample\bin\Debug\IEDriverServer.exe

The relative path to that is:

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

If its C:\Users\kamal\Documents\Sample\Sample\bin\Debug\netcoreapp3.1\IEDriverServer.exe

you can use driver = new InternetExplorerDriver(".", options);

More detailed the paths are like this:

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
查看更多