测试脚本不在特定页面等待

Test script is not wait in specific page

driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);
driver.FindElement(By.XPath(".//*[@class = 'search-box']")).SendKeys("Samsung");
Console.WriteLine("confirm!");

driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);
driver.FindElement(By.XPath(".//*[@class = 'search-icon']")).Click();
Console.WriteLine("confirm!");

driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);
driver.FindElement(By.ClassName("fvrt-btn")).Click();
Console.WriteLine("confirm!");

driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);
driver.FindElement(By.XPath(".//*[@class = 'link-text']/div/div/div/div[a]/div/div/div")).Click();
Console.WriteLine("confirm!");

driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);
driver.FindElement(By.ClassName("ufvrt-btn")).Click();
Console.WriteLine("confirm!");

// 此行无效,测试脚本未在特定页面等待。 driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);

您应该使用显式等待而不是隐式等待。试试这个:

WebDriverWait wait;
wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.visibilityOfElementLocated(element));

其中 element 是元素定位器,例如代码第二行的 By.XPath(".//*[@class = 'search-box']")
等待超时通常设置为 30 秒以允许页面完全加载。