2

Test is very slow during execution of the script without knowing the reason.

This is my script :

driver.Navigate().GoToUrl(url);       
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(20);
driver.FindElement(By.LinkText("Register Here")).Click();
new WebDriverWait(driver, TimeSpan.FromSeconds(10)).Until(
    SeleniumExtras.WaitHelpers.ExpectedConditions.InvisibilityOfElementLocated(
        (By.XPath("//div[@class='loader-wrapper    ng-trigger ng-trigger-visibilityChanged ng-animating']"))));
driver.FindElement(By.XPath("(.//*[normalize-space(text()) and    normalize-space(.)='Organization    Type'])[2]/following::select[1]")).Click();
new SelectElement(driver.FindElement(By.XPath("(.//*[normalize-space(text())    and normalize-space(.)='Organization    Type'])[2]/following::select[1]"))).SelectByText("Hospital");
driver.FindElement(By.XPath("(.//*[normalize-space(text()) and    normalize-space(.)='Organization    Type'])[2]/following::button[1]")).Click();
new WebDriverWait(driver, TimeSpan.FromSeconds(10)).Until(
    SeleniumExtras.WaitHelpers.ExpectedConditions.InvisibilityOfElementLocated(
        (By.XPath("//div[@class='loader-wrapper    ng-trigger ng-trigger-visibilityChanged ng-animating']"))));
driver.FindElement(By.XPath("(.//*[normalize-space(text()) and    normalize-space(.)='Phone    Number'])[1]/following::button[1]")).Click();
new WebDriverWait(driver, TimeSpan.FromSeconds(10)).Until(
    SeleniumExtras.WaitHelpers.ExpectedConditions.InvisibilityOfElementLocated(
        (By.XPath("//div[@class='loader-wrapper    ng-trigger ng-trigger-visibilityChanged ng-animating']"))));

try
{
    Assert.AreEqual("Title is Required.", driver.FindElement(By.XPath("(.//*[normalize-space(text()) and    normalize-space(.)='Title'])[1]/following::span[1]")).Text);
}
catch (Exception e)
{
    verificationErrors.Append(e.Message);
}

Any suggestion how to make the test faster ?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
James Fallon
  • 154
  • 1
  • 6
  • 17

1 Answers1

1

A simple step to make your script/program faster would be to:

  • Remove all the instances of ImplicitWait as:
    • You are extensively using WebDriverWait i.e. Explicit Wait

As per the documentation of Explicit and Implicit Waits:

WARNING: Do not mix implicit and explicit waits. Doing so can cause unpredictable wait times. For example setting an implicit wait of 10 seconds and an explicit wait of 15 seconds, could cause a timeout to occur after 20 seconds.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • exactly this what is happening,but i need the implicit time out first because website take time to load and was giving me an error.. As for explicit wait i dont know how to solve this because i have a loader and this loader obscured another element. So what you suggest me to do instead of repeating explicit wait and implicit wait – James Fallon Aug 29 '18 at 09:43
  • `ImplicitWait` will soon die in _fire_. Don't rely on `ImplicitWait` any more. Use tailor made `Explicit wait` for all your needs. _Loader_ can be solved with a much simpler approach. – undetected Selenium Aug 29 '18 at 09:46
  • this my loader method to be invisible : wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.InvisibilityOfElementLocated(By.XPath("//div[@class='loader-wrapper ng-trigger ng-trigger-visibilityChanged ng-animating']"))); I have a loader in more than one page so i need to add more than one of the above method – James Fallon Aug 29 '18 at 09:48
  • Perhaps you were too early to implement the first available solution to your most important question [Element is not clickable another element receive the click- Selenium c#](https://stackoverflow.com/questions/52034706/element-is-not-clickable-another-element-receive-the-click-selenium-c-sharp). You need to wait a bit for the contributors to construct good answrs to your questions. – undetected Selenium Aug 29 '18 at 09:48
  • i removed the accept answer from the previous question.. i am waiting to new suggest..:) – James Fallon Aug 29 '18 at 09:51
  • @JamesFallon I can see there is a separate question for _ExpectedConditions.InvisibilityOfElementLocated_. Let us keep this issue separate from this existing issue of **Selenium Webdriver is very slow** – undetected Selenium Aug 29 '18 at 09:52
  • @JamesFallon It's not a good practice to remove the acceptance from an answer which solved your question/purpuse. I suggest referring to the existing (accepted) answer, you can always raise a question for further improvement. – undetected Selenium Aug 29 '18 at 09:55
  • 1
    ok i just re-accepted the answer there. but still need a better solution. As you mention here that i can avoid the test being slow by usng explicit instead of implicit ? – James Fallon Aug 29 '18 at 09:58