-2

I am trying to test using selenium. I want to click a button but i have a loader that wait couple of second before disappear.

Loader element who is overlaying other element.You can see here how loader look like in my page. So i need a help to find a way to wait until this loader disappear to continue my test

image

Error:

OpenQA.Selenium.WebDriverException
  HResult=0x80131500
  Message=unknown error: Element <select _ngcontent-c4="" class="col-xs-8 custom-input-styles custom-select ng-touched ng-dirty ng-valid" formcontrolname="organizationType">...</select> is not clickable at point (441, 620). Other element would receive the click: <div _ngcontent-c2="" class="loader-wrapper ng-trigger ng-trigger-visibilityChanged ng-animating" style="">...</div>
  (Session info: chrome=68.0.3440.106)
  (Driver info: chromedriver=2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab),platform=Windows NT 10.0.17134 x86_64)
  Source=WebDriver
  StackTrace:
   at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
   at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
   at OpenQA.Selenium.Remote.RemoteWebElement.Execute(String commandToExecute, Dictionary`2 parameters)
   at OpenQA.Selenium.Remote.RemoteWebElement.Click()
   at BnI.UITests.Register.TheProceedRedirectTest() in C:\Users\me\UITests\Register.cs:line 86
jack daniels
  • 11
  • 1
  • 3
  • Please run that in firefox and share the error message, it would tell you which element has overlaying your element, we can code by using that element. – Rajagopalan Aug 24 '18 at 10:46
  • i edited my question – jack daniels Aug 24 '18 at 10:48
  • If you show the picture, how can I able to understand? Think of person who is trying to resolve your problem. If you run in the firefox, it would tell you which element is overlaying your element in that error message, so paste it here. Here is my answer related to this kind of problem. https://stackoverflow.com/questions/51841884/python-selenium-finds-clickable-element-that-cannot-be-clicked/51842120#51842120 – Rajagopalan Aug 24 '18 at 10:52
  • man this loader element who is overlaying other element – jack daniels Aug 24 '18 at 10:54
  • I understand due, I want to know the html of that loader element. See my answer to the other question where how error message appears. – Rajagopalan Aug 24 '18 at 10:55
  • check now my question – jack daniels Aug 24 '18 at 10:58

2 Answers2

0

If you know the class name of the loader, you just can add the below code snippet (for c#):

WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(seconds));
            var waiter = wait.Until(ExpectedConditions.InvisibilityOfElementLocated(By.ClassName(cssClass)));
            return waiter;
Mike
  • 4,041
  • 6
  • 20
  • 37
Techno
  • 91
  • 6
  • I know this method and it's correct but assum if i have more than button i should repeat the same code at each button or if i have i field also i should repeat this in every field cssclass – jack daniels Aug 24 '18 at 11:33
0

You just need to wait for jquery to finish its job. Here's a sample java implementation of the solution that I have come up.

I don't use WebDriverWait as I must define a TimeOut. This script will wait for the jquery to finish its job even if it takes 10 minutes. I have tried this in a demo website where I preconfigured a hard coded wait of 7 minutes. And It worked for me.

//Wait for JQuery Load
public static void waitForJQueryLoad() {
    //Wait for jQuery to load
    ExpectedCondition<Boolean> jQueryLoad = driver -> ((Long) ((JavascriptExecutor) jsWaitDriver)
            .executeScript("return jQuery.active") == 0);

    //Get JQuery is Ready
    boolean jqueryReady = (Boolean) jsExec.executeScript("return jQuery.active==0");

    //Wait JQuery until it is Ready!
    if(!jqueryReady) {
        System.out.println("JQuery is NOT Ready!");
        //Wait for jQuery to load
        jsWait.until(jQueryLoad);
    } else {
        System.out.println("JQuery is Ready!");
    }
}

If it's something other than JQuery. Just take a look at the sample provided in that web site(https://www.swtestacademy.com/selenium-wait-javascript-angular-ajax/). You may end up with Angular, JQuery and XHR request solutions also.

  • i am using angular instead of jquery – jack daniels Aug 24 '18 at 11:59
  • Then check the waitForAngularLoad() method in the link. That might give you an idea. In case you want to check the state of Angular on your page, you may execute "return angular.element(document).injector().get('$http').pendingRequests.length === 0" command on your browsers console and see the result. If it's more that 1, then there's an angular event processing. You should wait for it to became 0 – Canberk Akduygu Aug 24 '18 at 12:02
  • can i add it at the end of my unit test ? – jack daniels Aug 24 '18 at 12:06
  • If you end up at the end, it wouldnt have any affect at all. You just have to place it before you click. Actually, create a findElement method and place this method at the beginning of it and use custom findElement in every find action so you dont have to worry copy pasting this code. – Canberk Akduygu Aug 24 '18 at 13:14
  • but this method is not working with c# ?! – jack daniels Aug 24 '18 at 13:49
  • Thats why i wrote "this is a java implementation". You should convert it to C# – Canberk Akduygu Aug 24 '18 at 13:53
  • thanks but i dont think this will work – jack daniels Aug 24 '18 at 13:56