【问题标题】:Selenium WebdriverTimeoutException although the page is already loadedSelenium WebdriverTimeoutException 尽管页面已经加载
【发布时间】:2020-09-04 13:02:16
【问题描述】:

我是 Selenium 新手,并尝试以全屏模式自动打开网站。

  • 该网站有一个登录,它已经在使用 Selenium。
  • 登录后只需按下一个按钮。

因此,WebdriverTimoutException 在倒数第二行抛出。

  • InnerException 表示NoSuchElementException
  • 但是当我打开 Web 控制台时,我可以看到按钮。
IWebDriver driver = new EdgeDriver(System.IO.Directory.GetParent(System.IO.Directory.GetParent(Environment.CurrentDirectory).ToString()).ToString() + "\\webdriver");

driver.Navigate().GoToUrl(@"http://examplehomepage.com");

driver.FindElement(By.Id("username")).SendKeys("abc");
driver.FindElement(By.Id("password")).SendKeys("password123");
driver.FindElement(By.TagName("button")).Click();

driver.Manage().Window.FullScreen();

WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30));

IWebElement element = wait.Until(ExpectedConditions.ElementToBeClickable(By.TagName("button")));

element.Click();

我试过了:

  • 边缘 (85.0.564.44)
  • 铬 (85.0.4183.83)
  • 火狐(80.0.1)。

【问题讨论】:

  • 您需要发布元素的相关HTML。您可以检查元素是否存在于任何 iframe?
  • 在你提到它之后,我注意到整个仪表板都在 iframe 中。
  • 您需要先切换到iframe 才能访问该元素? driver.SwitchTo().Frame("frame-id");
  • 使用 driver.SwitchTo().Frame("frame-id");确实解决了我的问题。非常感谢:)

标签: c# selenium selenium-webdriver geckodriver selenium-edgedriver


【解决方案1】:
  1. 您可以使用睡眠来延迟交互
  2. 您正在使用 ElementToBeClickable。您还应该使用 ElementToBeVisible 并通过 isEnabled 函数检查元素是否已启用。

【讨论】:

  • 您好,感谢您的回答,但我已经尝试了这两种解决方案。它没有用。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-08-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-04-04
相关资源
最近更新 更多