【问题标题】:Application is not getting identified using CSS selectors working with Internet explorer browser version 11使用与 Internet Explorer 浏览器版本 11 配合使用的 CSS 选择器未识别应用程序
【发布时间】:2020-08-10 21:01:12
【问题描述】:

我在 IE 浏览器上使用“http://automationpractice.com/index.php”进行 POC 当我通过“登录”按钮导航时,电子邮件文本框的这种识别变得疯狂并且没有被脚本识别。 我使用 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。

感谢您的帮助。

【问题讨论】:

  • 我能找到它们,提供错误信息。试试 xpath //input[@id='email_create']
  • 消息:OpenQA.Selenium.NoSuchElementException:找不到元素:By.XPath://input[@id='email_create']

标签: c# selenium-webdriver internet-explorer-11 browser-automation selenium-iedriver


【解决方案1】:

我尝试使用 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);
                }

        }
    }

输出:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-04-12
    • 2012-11-29
    • 1970-01-01
    • 2016-07-01
    • 2020-10-02
    • 1970-01-01
    • 1970-01-01
    • 2011-11-16
    相关资源
    最近更新 更多