如何在IE驱动程序的C#硒中设置相对路径 [英] How to set a relative path in C# selenium for IE driver
问题描述
在下面的代码中,我的本地计算机上提供了IEDriverServer.exe.我想在不同的机器上运行此代码.在C#中获取IEDriverServer.exe时如何设置相对路径.
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();
推荐答案
如果文件路径为C:\ Users \ kamal \ Documents \ Sample \ Sample \ bin \ Debug \ IEDriverServer.exe
If the path to the file is 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
If its 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
这篇关于如何在IE驱动程序的C#硒中设置相对路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!