簡體   English   中英

IE驅動如何在C# selenium中設置相對路徑

[英]How to set a relative path in C# selenium for IE driver

在下面的代碼中,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:\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 Inte.netExplorerDriver(".", 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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM