0

The framework which we were using Selenium-RC, now we are converting it to Webdriver. I tried to search the alternative code of below one, but couldn't find.

Since the code is used n number of times in framework its on priority to fix

**selenium.waitForCondition(script, timeout);**

//The complete code is below

public void waitForAjaxToComplete() {
        String waitCondition = "";
        for (JsToolkit kit : JsToolkit.values()) {
            waitCondition += waitCondition.equalsIgnoreCase("") ? kit.waitCondition() : " && " + kit.waitCondition();
        }
        waitCondition += " && (null == selenium.browserbot.getCurrentWindow().event)";
        try {
            selenium.waitForCondition(waitCondition, getDefaultPageWaitTime());
        } catch (Exception e) {
            logger.warn(e.getMessage());
        }
    }

// JS toolkit is an ENUM

public enum JsToolkit {
    DOJO("dojo", "dojo.io.XMLHTTPTransport.inFlight.length==0"), EXTJS("Ext",
            "Ext.Ajax.isLoading()==false"), JQUERY("jQuery", "jQuery.active==0"), YUI("YAHOO",
                    "YAHOO.util.Connect.isCallInProgress==false"), PHPJS("PHP_JS",
                            "PHP_JS.resourceIdCounter==0"), PROTOTYPE("Ajax", "Ajax.activeRequestCount==0");

    String identifier;
    String expr;

    private JsToolkit(String identifier, String expr) {
        this.identifier = identifier;
        this.expr = expr;
    }



    public String waitCondition() {
        return "return " + getExpr() +";";
    }

    public static String globalWaitCondition() {
        StringBuilder sb = new StringBuilder("return ");
        for(JsToolkit toolkit: JsToolkit.values()){
            sb.append(" ("+ toolkit.getExpr() + ") &&");
        }
        sb.append(";");
        return sb.toString().replace(" &&;", ";");
    }

    public String getExpr(){
        return "((typeof "+ identifier +" === 'undefined') || (" + expr + "))";
    }
}

Selenium RC ---> selenium.waitForCondition(script, timeout); Selenium WebDriver ----> ????

Nakul
  • 61
  • 1
  • 7
  • Check if this helps, https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/support/ui/ExpectedConditions.html – Kamal Mar 25 '19 at 05:40
  • From what I can tell from some quick googling, `script` is just some JavaScript code that is to be executed until `timeout` is reached. That part is easy to replace using `JavascriptExecutor` like [this](https://stackoverflow.com/questions/11430773/how-to-use-javascript-with-selenium-webdriver-java). The bigger problem you are going to have is replacing the different JS functions that seem to be available from Selenium-RC. You will have to figure out what they do and come up with replacements for each. – JeffC Mar 25 '19 at 20:46
  • I think you would be better off converting them to `WebDriverWait`s instead of trying to do some direct translation. It will be a little more work at first but easier to maintain. – JeffC Mar 25 '19 at 20:47

1 Answers1

0

I'm not sure I understood your question.

Are you looking for a way to do implicit and explicit waits using Selenium WebDriver?

If so, maybe you can check this out? Selenium WebDriver Wait Commands

Rue
  • 1
  • 3
  • I am well versed with WebDriver wait, but those are specific waits. either it be Implict,explicit or fluent, all of those wait are applied for specific element until it appears or timeout (whichever comes first). My question was is there any generic wait method in WebDriver like RC had which takes script as an argument. – Nakul Mar 26 '19 at 04:44
  • Oh okay. I have no knowledge of a way to do that. Please share if you find it :) – Rue Apr 02 '19 at 12:29