javascriptjavaselenium-webdriverprimefaces

How to use widgetVar in Javascript in Selenium in Java with PrimeFaces?


Javascript is working after setting the option:

chromeOptions.addArguments("--enable-javascript");

But I am still looking on how to use widgetVar from PrimeFaces to get hold of a PrimeFaces widget.

I tried:

private static boolean isContentByWidgetVarProDriver(RemoteWebDriver driver, String driverName, String content, String widgetVar) {
        WebElement value = null;
        try {
            value = (WebElement) driver.executeScript("return PF('domains_counter');", driver.findElement(By.id("main")));
            if (value.getText().contains(content)) {
                return true;
            }
        } catch (Exception e) {
            LOGGER.info("Test failed on {}:\nSelector was '{}' but value '{}' could not be read. '{}' was expected as content.", driverName, widgetVar, value, content);
        }
        return false;
    }

But it returns null.

In the browser console it works.

browser console


Solution

  • Heureka!

    This is the solution:

    driver.executeScript("return PrimeFaces.widgets.domains_counter_panel.content[0].innerText");
    

    or in general: PrimeFaces.widgets.~~~

    where ~~~ is the widgetVar of the widget!!!