在以下代码中
using System;
using System.Security.Policy;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Support;
using OpenQA.Selenium.Support.PageObjects;
namespace StackOverflowTest
{
class Program
{
static void Main(string[] args)
{
IWebDriver driver = new ChromeDriver();
driver.Navigate().GoToUrl("http://www.stackoverflow.com");
driver.FindElement(By.LinkText("log in")).Click();
driver.FindElement(By.ClassName("google-login")).Click();
Int16 myInt = 2; //breakpoint goes here.
driver.Close();
}
}
}Selenium正在抛出一个“NoSuchElement”异常。然后,当我点击“继续”时,它会单击它应该找不到的元素。有人能向我解释一下为什么会这样吗?我做错了什么?
发布于 2016-04-05 20:32:01
该元素的加载可能需要一段时间。可以在ExpectedConditions中使用显式等待以等待元素
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
wait.Until(ExpectedConditions.ElementIsVisible(By.LinkText("log in"))).Click();或设置隐式等待
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));https://stackoverflow.com/questions/36436228
复制相似问题