How to check if toggle button is selected or not in Truclient


 Hi ,

I'm using truclient protocol for scripting im stuck at a point, there is toggle button on clicking the toggle button it will subscribe or unsubcribe. Intially the toggle button is off im clicking it will subscribe and turns blue toggle button_selected.png

 can any one help me how to check if it is subscribed??





1 Reply
Fleet Admiral
Fleet Admiral


Unlike a checkbox which is pretty standard, there are different implementations to toggle buttons. Usually the on/off indication is managed by CSS (HTML Styling), hence it is not straight forward to generalize it to a simple API.

In W3Schools example the on/off indication is done by CSS using background color indication and the location of the toggle of the button inside the background, which is also controlled by CSS. Behind the scenes there is also a hidden checkbox that maintains the state.

If you wish to identify if the toggle is on or off using TruClient you can use a "Generic Object Action" step, select the element, change the Action from Click to "Evaluate JavaScript on Object" and in the evaluation code write something like below example


// Get the object style since the toggle is visualized using background-color
// The object is identified by TruClient. This is the object identified in the Object section
var style = window.getComputedStyle(object);

// get the background color value var bgcolor = style.getPropertyValue('background-color');

// rgb(33, 150, 243) means checked in this example if (bgcolor == "rgb(33, 150, 243)") window.alert("checked") else window.alert(bgcolor)

You can write your own code in the if/else sections based on your desired logic. Alternatively you can use also TruClient If/Else step and control the flow based on the toggle button state.

You will probably have to examine the DOM in your application and reach to the concrete logic required for your application

I know it is not trivial, but it is not that hard either.

Hope it helps






The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.