如果我使用Chrome或Firefox驱动程序,我会继续:
没有这样的元素:无法找到元素:{"方法":" css选择器","选择器":"#id-of-元素"} (会议信息:chrome = 59.0.3071.115) (驱动程序信息:chromedriver = 2.31.488763(此处为长十六进制代码),platform = Windows NT 10.0.15063 x86_64)
我去了同一个网页并将其存储在本地。当我将webdriver指向本地文件时,它可以找到输入元素并用SendKeys
网站的在线版本是否有可能对硒有某种保护作用?喜欢蒸馏?
我也尝试通过id或xpath获取元素。我等了,我使用了这些扩展方法:
public static class WebDriverExtensions
{
public static IWebElement FindElement(this IWebDriver driver, By by, int timeoutInSeconds)
{
if (timeoutInSeconds > 0)
{
//return new WebDriverWait(driver, TimeSpan.FromSeconds(timeoutInSeconds)).Until(ExpectedConditions.ElementExists(by));
return new WebDriverWait(driver, TimeSpan.FromSeconds(timeoutInSeconds)).Until(ExpectedConditions.ElementIsVisible(by));
}
return driver.FindElement(by);
}
public static ReadOnlyCollection<IWebElement> FindElements(this IWebDriver driver, By by, int timeoutInSeconds)
{
if (timeoutInSeconds > 0)
{
//return new WebDriverWait(driver, TimeSpan.FromSeconds(timeoutInSeconds)).Until(ExpectedConditions.ElementExists(by));
return new WebDriverWait(driver, TimeSpan.FromSeconds(timeoutInSeconds)).Until(ExpectedConditions.VisibilityOfAllElementsLocatedBy(by));
}
return driver.FindElements(by);
}
}
Firefox提供的信息较少:
无法找到元素#id-of-element