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

查看:81
本文介绍了如何在IE驱动程序的C#硒中设置相对路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下面的代码中,我的本地计算机上提供了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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆