问题描述
在下面的代码中,我的本地计算机可用.我想在不同的机器中运行此代码.如何在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
问题描述
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