[使用Internet Explorer浏览器版本11的CSS选择器无法识别应用程序

问题描述 投票:0回答:1

我正在IE浏览器中将POC用作“ http://automationpractice.com/index.php”当我通过“登录”按钮导航时,这种对电子邮件文本框的标识正在变得疯狂,并且未被脚本标识。我使用CssSelectors进行识别,如下所述:


#email_create
input#email_create
input[id='email_create']
input[id*='email_create']
input[id^='email_create']
driver.findElement(By.CssSelector("MENTIONED ABOVE")).SendKeys("abc");

令人惊讶的是,这些选择器适用于Chrome,Firefox,但不适用于IE。

感谢您的帮助。

c# selenium-webdriver internet-explorer-11 browser-automation selenium-iedriver
1个回答
0
投票

我尝试使用IE 11浏览器在我这边测试您的代码。

在测试结果中,我发现您的代码正在运行,并且能够使用其ID搜索该元素。

当我尝试使用CssSelector]测试您的代码时,我发现它显示OpenQA.Selenium.NoSuchElementException错误。

我试图像下面那样修改代码,并且它可以与IE浏览器一起使用。

   driver.FindElement(By.CssSelector("input[id=email_create]")).SendKeys("abc");

完整代码:

class Program
    {
        private const string URL = @"http://automationpractice.com/index.php?controller=authentication&back=my-account";

        private const string IE_DRIVER_PATH = @"D:\D drive backup\selenium web drivers\";

        static void Main(string[] args)
        {
            var options = new InternetExplorerOptions()
            {
                InitialBrowserUrl = URL,
                IntroduceInstabilityByIgnoringProtectedModeSettings = true,
                ForceCreateProcessApi = true,
                //BrowserCommandLineArguments = "-private"
            };
            var driver = new InternetExplorerDriver(IE_DRIVER_PATH, options);

            driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(2);
            try
                {
                //var text = driver.FindElementById("email_create");
                //text.SendKeys("abc");

                driver.FindElement(By.CssSelector("input[id=email_create]")).SendKeys("abc");

                Console.WriteLine("success");
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }

        }
    }

输出:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.