Webdriver script that does an "IF" step
search cancel

Webdriver script that does an "IF" step

book

Article ID: 397690

calendar_today

Updated On: 05-15-2025

Products

CA App Synthetic Monitor

Issue/Introduction

I have a webdriver script that uses a redirection link to get to a target application link. 

Is there is a possibility to have an "IF" step?

Environment

DX ASM

Resolution

Use 'runScript' command and below example code or variations as a template:

 

(function() {

    var xpath = "//input[@value='Submit']";
    var result = document.evaluate(xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
    var button = result.singleNodeValue;

    if (button) {

        button.click();
        console.log("Submit button clicked.");

    } else {

      console.log("Submit button not found.");

    }

})();

Additional Information