The content of web pages can be displayed conditionally. Simply put, the page content can be changed dynamically based on different factors such as geo-location, user role, or IP address. For example, a welcome-wizard modal for new users or a text box with different content depending on the locale can be presented on the page. To monitor DOM elements in this case, you can customize the recorded monitoring script with selection statements.

To create a dynamic script that does something different based on the web element displayed on the web page, add if-else statement to the script in the desktop version of EveryStep Scripting Tool.

For inline script editing, enable the Allow to edit script manually feature in the Advanced Settings menu. See also EveryStep Scripting Tool: classes, methods, properties, etc.

If-else statement example

Delay ("6sec".ToDuration ());

if (tab0.IsElementPresented("//BUTTON[@ID=\"start\"]/STRONG[normalize-space(text())=\"Edit order\"]")){
tab0.Element ("//BUTTON[@ID=\"start\"]/STRONG[normalize-space(text())=\"Edit order\"]").Click ();
Delay ("3sec".ToDuration ());
if (tab0.IsElementPresented("//INPUT[@ID=\"chkOrder\"]")) tab0.Element ("//INPUT[@ID=\"chkOrder\"]").Click ();
Delay ("1sec".ToDuration ());
if (tab0.IsElementPresented("//BUTTON[@ID=\"btnClose\"]")) tab0.Element ("//BUTTON[@ID=\"btnClose\"]").Click ();
Delay ("1sec".ToDuration ());
if (tab0.IsElementPresented("//BUTTON[@ID=\"end\"]/STRONG[normalize-space(text())=\"End session\"]")) tab0.Element ("//BUTTON[@ID=\"end\"]/STRONG[normalize-space(text())=\"End session\"]").Click ();
Delay ("5sec".ToDuration ());
}
else if (tab0.IsElementPresented("//BUTTON[@ID=\"start\"]/STRONG[normalize-space(text())=\"Start shopping\"]")) {
tab0.Element ("//BUTTON[@ID=\"start\"]/STRONG[normalize-space(text())=\"Start shopping\"]").Click ();
Delay ("1sec".ToDuration ());
tab0.Element ("//INPUT[@ID=\"chkBalance\"]").Click ();
Delay ("1sec".ToDuration ());
tab0.Element ("//BUTTON[@ID=\"btnOk\"]").Click ();
Delay ("1sec".ToDuration ());
if (tab0.IsElementPresented("//INPUT[@ID=\"chkOrder\"]")) tab0.Element ("//INPUT[@ID=\"chkOrder\"]").Click ();
Delay ("1sec".ToDuration ());
if (tab0.IsElementPresented("//BUTTON[@ID=\"btnClose\"]")) tab0.Element ("//BUTTON[@ID=\"btnClose\"]").Click ();
Delay ("1sec".ToDuration ());
if (tab0.IsElementPresented("//BUTTON[@ID=\"end\"]/STRONG[normalize-space(text())=\"End session\"]")) tab0.Element ("//BUTTON[@ID=\"end\"]/STRONG[normalize-space(text())=\"End session\"]").Click ();
}
}