-1
我尝试发送键输入字段,但不能做到这一点...... 我已经尝试了不同的方式来等到元素是可见的,但有超时异常......硒ChromeDriver - 元素从来没有看到
IWebElement userName = driver.FindElement(By.Id("UserName"));
IWebElement userPassword = driver.FindElement(By.Id("Password"));
IWebElement subButton = driver.FindElement(By.XPath(("//button[contains(.,'Вхід')]")));
while (true)
{
userName = driver.FindElement(By.Id("UserName"));
if (userName.Displayed)
{
userName.SendKeys("test");
break;
}
}
subButton.Click();
使用这种方法让我总是超时:
public static void WaitForElementLoad(By by, int timeoutInSeconds)
{
if (timeoutInSeconds > 0)
{
WebDriverWait wait = new WebDriverWait(webDriver, TimeSpan.FromSeconds(timeoutInSeconds));
wait.Until(ExpectedConditions.ElementIsVisible(by));
}
}
很难不检查这个网站,看着HTML代码来回答。一些提示:检查'id = UserName'是否在页面内是唯一的,理论上它必须是唯一的,但开发人员可能不知道这一点,并添加了两个具有相同ID'用户名'的元素。 – krokodilko
明显的结论似乎是元素不可见。检查你的定位器,并确保它们是唯一的,并找到你想要的元素。 – JeffC
请分享HTML或URL \ – iamsankalp89