问题描述
我是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函数中检查元素是否也已启用。