Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Selenium C#-模拟后运行Selenium驱动程序时出现异常_C#_Selenium - Fatal编程技术网

Selenium C#-模拟后运行Selenium驱动程序时出现异常

Selenium C#-模拟后运行Selenium驱动程序时出现异常,c#,selenium,C#,Selenium,我正在使用windows功能“模拟”,在启动Chrome驱动程序之前更改活动用户。现在,在没有模拟代码的情况下启动驱动程序就可以了。模拟代码也可以正常工作;我看到用户已更改。但是,当发生此更改时,然后我运行IWebDriver=new ChromeDriver,然后在该代码上触发异常,测试停止。你知道为什么会这样吗 下面是所使用代码的主要部分(代码只是stackoverflow上另一篇文章中的一点修改代码) 发现了问题。D用户没有chrome驱动程序i Bin文件夹的权限发现问题。D用户没有ch

我正在使用windows功能“模拟”,在启动Chrome驱动程序之前更改活动用户。现在,在没有模拟代码的情况下启动驱动程序就可以了。模拟代码也可以正常工作;我看到用户已更改。但是,当发生此更改时,然后我运行
IWebDriver=new ChromeDriver
,然后在该代码上触发异常,测试停止。你知道为什么会这样吗

下面是所使用代码的主要部分(代码只是stackoverflow上另一篇文章中的一点修改代码)


发现了问题。D用户没有chrome驱动程序i Bin文件夹的权限

发现问题。D用户没有chrome驱动程序i-Bin文件夹的权限

请发布您的代码
IWebDriver=new ChromeDriver
还不够。嗨,我在回家的路上在电话上写了这篇文章,所以我没有可用的代码。现在我已经在最初的帖子中添加了它。在我编写模拟代码时(我看到用户已更改),selenium代码分别工作。但是selenium驱动程序不起作用,它就停在那里。请发布您的代码
IWebDriver=new ChromeDriver
还不够。嗨,我在回家的路上在电话上写了这篇文章,所以我没有可用的代码。现在我已经在最初的帖子中添加了它。在我编写模拟代码时(我看到用户已更改),selenium代码分别工作。但是,如果selenium驱动程序不起作用,它就会停在那里。
namespace localSeleniumTest.Impersonation
{
    class Program
    {
        [DllImport("advapi32.dll", SetLastError = true)]
        public static extern bool LogonUser(stringpszUsername, string pszDomain, string pszPassword,
            int dwLogonType, int dwLogonProvider, ref IntPtr phToken);

        // closes open handes returned by LogonUser
        [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
        public extern static bool CloseHandle(IntPtr handle);

        public void Impersonation()
        {
            WindowsImpersonationContext impersonationContext = null;
            IntPtr userHandle = IntPtr.Zero;
            const int LOGON32_PROVIDER_DEFAULT = 0;
            const int LOGON32_LOGON_INTERACTIVE = 2;
            string domain = Config.domain;
            string user = Config.username;
            string password = Config.password;

            try
            {
                String currentName = WindowsIdentity.GetCurrent().Name;

                // if domain name was blank, assume local machine
                if (domain == "")
                    domain = System.Environment.MachineName;

                // Call LogonUser to get a token for the user
                bool loggedOn = LogonUser(
                    user,
                    domain,
                    password,
                    LOGON32_LOGON_INTERACTIVE,
                    LOGON32_PROVIDER_DEFAULT,
                    ref userHandle
                    );

                if (!loggedOn)
                {
                    return;
                }

                // Begin impersonating the user
                impersonationContext = WindowsIdentity.Impersonate(userHandle);

                String afterImpersonationName = WindowsIdentity.GetCurrent().Name;


                /*this few lines below does not work after impersonation but 
work perfectly without the code above.*/
                    IWebDriver driver = new ChromeDriver();
                    driver.Navigate().GoToUrl("www.google.com");
                    System.Threading.Thread.Sleep(6000);
                    driver.Quit();