Tips for utilizing widgetVar in Javascript within Selenium framework using Java and PrimeFaces framework

After incorporating the option below, Javascript started functioning:

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

However, I am still in search of a way to utilize widgetVar from PrimeFaces in order to access a PrimeFaces widget.

I attempted:

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;
    }

Yet, it outputs null.

It does function in the browser console.

https://i.sstatic.net/08yrlvCY.png

Answer №1

Aha!

Here's the answer:

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

or more broadly: PrimeFaces.widgets.~~~

where ~~~ represents the widgetVar of the widget!!!

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

JQuery: Creating a visually striking screen flash

How can I make the window or page flash/blink using JQuery or plain JavaScript? I also want to get the tab to flash at the same time. Currently, the code I have is: var flash = true; var alert = setInterval(function(){ if (flash) //doFlash ...

Acquiring Backlinks from an Interactive Website

Hi there, I've been working on scraping all the links from a JS-based dynamic webpage that has a load more option. I tried triggering the page to scroll down, but unfortunately, I only managed to retrieve 103 links. I'm having trouble fixing my ...

What is the process for adding extra CSS to a webpage displayed in WebView2?

Currently, I am utilizing the Webview2 control within a winform application. My goal is to enhance the behavior of the loaded page by injecting additional CSS code when a specific URL is being displayed in the browser control. Specifically, I aim to implem ...

Strategies for extracting methods and refactoring to a separate file for better reusability

Still relatively new to the JQuery/javascript realm, I've put together a functional jqgrid with a datepicker and custom control (using jquery auto complete) by piecing together code samples I came across online. This code has been added to a T4 templa ...

Audio in A-Frame does not function properly when in VR mode

My friend and I are collaborating on a small project involving a VR simulation that requires audio instructions. While everything functions smoothly in the web version and even on mobile devices, we encountered an issue when switching to VR mode on mobile ...

What could be causing my selenium tests to fail on travis-ci even though there have been no code changes, when they are passing successfully

I'm facing a tough challenge trying to troubleshoot a selenium test that passes when run locally but not on travis. Reviewing the travis build logs, I noticed that the test was passing in build #311 but started failing at build #312. It seems like th ...

Accessing input fields within an HTML form using Selenium.Note: Please provide

I am struggling to select input fields from this specific form in Selenium. Despite trying multiple methods, my test consistently fails. Here is the HTML form in question: `<form class="login" action="/Index/trylogin/?ru=L015RmlueWE=" novalidate> ...

What is the process to retrieve the username from my system and display it in a web browser?

Seeking assistance to retrieve my system's username and display it on a web browser. Currently, I have been using ActiveXObject method, which successfully retrieves the username, but has drawbacks such as requiring ActiveX to be enabled and only works ...

Selenium testing - Immediate disappearance of OK/Cancel popup

Something strange is happening here. When I manually test this, I click the delete button, wait for the popup to appear https://i.sstatic.net/6PMS4.png and then click OK to remove the record successfully. However, when I attempt the same process in Java/Se ...

I am looking to create a div that can consistently refresh on its own without needing to refresh

I have implemented a comment system using ajax that is functioning well. I am looking to incorporate an ajax/js code to automatically refresh my "time ago" div every 5 seconds so that the time updates while users are viewing the same post. Important note: ...

I am facing difficulties installing packages such as react-bootstrap on my dashboard

Encountering an issue with installing packages in my dashboard. For example, attempting to install react-bootstrap results in the following error: node version: 12.16.1 npm version: 6.13.4 gyp ERR! UNCAUGHT EXCEPTION gyp ERR! stack Error: Cannot find mo ...

Display the keyboard on IOS when an input field is selected

I'm facing an issue that seems to have no solution. When using input.focus() on IOS, the keyboard doesn't appear searchMobileToggle.addEventListener('click', function() { setTimeout(function(){ searchField.focus(); ...

Fetch data dynamically with jQuery AJAX

I am working on a jQuery Ajax form submission to a PHP page with the goal of dynamically returning values instead of all at once. For instance, in my jQuery code: jQuery.ajax({ type: "POST", url: "$PathToActions/Accounts.php", dataType: ...

Looking for a straightforward way to incorporate a "Read more" and "Show Less" functionality into a Wordpress site using Javascript?

As a last resort, I am seeking a quick and simple fix. I have been experimenting with Javascript to implement a 'Read more...' & '... Read Less' feature on six different sections of a single page. The goal is to display only the fi ...

Create a new array in JavaScript by comparing and finding the differences between two existing arrays

I have two arrays - array1 and array2. I want to compare both arrays and create a new array (array3) with values that are unique to array1. For example, 'mob2', 'pin', 'address2', 'city' are present in array1 but no ...

When calling undefined typescript, the async function does not return a value but displays its result afterwards

When I debug my function, it waits until the return statement, but when I call the function, it returns undefined and the errors are also undefined. I'm not sure why this is happening. import userModel from '../Models/user.model'; const bcr ...

Trouble linking JavaScript and CSS files in an Express App

Could someone assist me in understanding what is causing my code to malfunction? Why is it that my javascript and css files do not execute when the server sends the index.html file to the browser? I have a simple setup with an html page, javascript file, ...

Verifying Value Equality in all Documents with MongoDB

One feature on my website allows users to input a number into the field labeled subNum in a form. Upon submission of the form, I need to validate whether the entered value already exists within any existing document. This validation process is implemented ...

Retrieve information from an HTML table on a website and transfer it to a spreadsheet in Excel

I'm looking for assistance with extracting data from a website using VBA. I have an Excel table with ETF tickers, links, and prices, and I'm attempting to retrieve the previous day's closing price from each link using VBA. The challenge I&ap ...

Putting in selenium-java-2.5.0 into Eclipse

Recently, I downloaded "selenium-java-2.5.0" and included it in the build path of my project in eclipse. However, upon attempting to use one of the new API's, a syntax error arises. Can someone direct me to a tutorial for installing selenium-java-2.5 ...