OpenQA.Selenium.NoSuchElementException:'没有这样的元素:无法找到元素:{“method”:“css

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

OpenQA.Selenium.NoSuchElementException:'没有这样的元素:无法找到元素:{“method”:“css选择器”,“selector”:“#Email”} (会话信息:chrome=116.0.5845.141)'

            IWebDriver driver = new ChromeDriver(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));
            driver.Navigate().GoToUrl("https://www.gmail.com/");
            IWebElement query = driver.FindElement(By.Id("Email"));
            query.SendKeys("[email protected]");
            query = driver.FindElement(By.Id("next"));
            query.Click();
            // now you just have to do the same for the password page

            driver.Quit();

我在尝试登录 chrome 时遇到此错误,如何解决?

c# asp.net .net core
1个回答
0
投票

我假设您想自动访问 Gmail 上的电子邮件。

  1. Gmail(一般为 Google)可能会阻止此类使用验证码和类似技术自动访问其网站的尝试。
  2. Google 的登录表单上没有 ID 为“Email”的 Form 元素。您可以通过从浏览器打开开发人员工具来亲自查看这一点。然后按 Ctrl+Shift+C。然后,当鼠标悬停时,您应该会看到显示的 ID。
  3. 对于密码输入,无法通过 ID 进行选择,因为从 google 输入的密码没有 ID。这可能也是为了阻止自动登录尝试。

此外,selenium 用于自动测试您自己的网站,而不是旨在自动化 gmail 或 google 等网站的工作流程。它还有自己独立的 chrome 实例,与您用来访问互联网的 chrome 实例不同。

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