1
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!");

// this line is not working, test script is not waiting at specific page. driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);

zizzygirl
  • 33
  • 7
  • 2
    `ImplicitWait` is used to wait x seconds for an element to be found on the current page. You are doing `.Click` on multiple elements, some of which may navigate to another page. So, in short, `ImplicitWait` isn't going to prevent the browser navigation. – Ryan Wilson Apr 15 '21 at 19:51
  • 1
    It looks like you may need to wait for a page to load before executing some of your code blocks, you can read more about awaiting a page load here [wait for page load in selenium](https://stackoverflow.com/questions/5868439/wait-for-page-load-in-selenium) – Ryan Wilson Apr 15 '21 at 19:58
  • thx i wil check it – zizzygirl Apr 15 '21 at 20:09
  • 2
    `ImplicitWait` should only be defined once in your code, not every time you want to find an element. You are mixing `ImplicitWait` with the usage of `ExplicitWait` – JD2775 Apr 15 '21 at 20:17
  • @JD2775 Sometimes there is a need to change implicit waiting period, but it is in rare cases. In general it is correct, implicit wait is defined once, in the beginning of the project. – vitaliis Apr 16 '21 at 01:20

1 Answers1

1

You should use explicit waits instead of implicit. Try this:

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

where element is the element locator, for example By.XPath(".//*[@class = 'search-box']") on the second line of your code.
The wait timeout is usually set to 30 seconds to allow the page to be loaded completely.

Prophet
  • 32,350
  • 22
  • 54
  • 79