如何解决Selenium WebdriverTimeoutException,尽管该页面已被加载
我是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)
- Chrome(85.0.4183.83)
- Firefox(80.0.1)。
解决方法
- 您可以使用睡眠来延迟互动
- 您正在使用ElementToBeClickable。您还应该使用ElementToBeVisible并从isEnabled函数中检查元素是否也已启用。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。