尝试使用 Selenium,创建了一个非常简单的示例
static void Main(string[] args)
{
using (IWebDriver driver = new InternetExplorerDriver())
{
driver.Navigate().GoToUrl("https://gmail.com");
IWait<IWebDriver> wait = new WebDriverWait(driver, TimeSpan.FromSeconds(2.00));
wait.Until(d => ExpectedConditions.ElementExists(By.Id("Email")));
Console.WriteLine("Page loaded ...");
IWebElement userNameElt = driver.FindElement(By.Id("Email"));
while (!userNameElt.Displayed)
{
Console.WriteLine("Page not finished loading yet ...");
Thread.Sleep(3000);
}
userNameElt.SendKeys("my@sample.com");
userNameElt.Submit();
IWebElement passwordElt = driver.FindElement(By.Id("Passwd"));
userNameElt.SendKeys("password");
userNameElt.Submit();
IWebElement submitBtnElt = driver.FindElement(By.Id("signIn"));
submitBtnElt.Click();
}
}
但它抱怨找不到元素
Started InternetExplorerDriver server (64-bit)
2.25.3.0
Listening on port 1423
Page loaded ...
Unhandled Exception: OpenQA.Selenium.NoSuchElementException: Unable to find element with id == Email
任何想法?