New Ranks & Badges For The Community!
Notice something different? The ranks and associated badges have gone "Star Fleet". See what they all mean HERE
Highlighted
Absent Member.
Absent Member.
1134 views

How to test either this element or that element case?

Jump to solution

In one of the testing page, either one of below elements have to exist:

<div class='classA'>ABCD</div>

<p class='classB'>EFG</p>

How do we test such case? 

 

Thanks.

 

0 Likes
1 Solution

Accepted Solutions
Highlighted
Micro Focus Frequent Contributor
Micro Focus Frequent Contributor
Since you say one of the two elements must exist then the solution is easy. Find just one of the two elements, if it exists then click it, if it doesnt exist then the other must so click the other. Pseudocode:

if (BrowserFind(HANDLE_DESKTOP, "//div[@class='classA']", false, 3000, true) = HANDLE_INVALID) then
BrowserClick("//div[@class='classB']|, BUTTON_Left, "classB"); // A doesn't exist so B must exist so click B
else
BrowserClick("//div[@class='classA']|, BUTTON_Left, "classB"); // A does exist so click it.
end;

View solution in original post

5 Replies
Highlighted
Absent Member.
Absent Member.
For Browser-Driven script you can insert a Verification Function during the script recording.
0 Likes
Highlighted
Absent Member.
Absent Member.
You can use WebVerifyHTMLBound function. Please see 'Setting Verification Options' in the SilkPerformer Documentation.
0 Likes
Highlighted
Absent Member.
Absent Member.
Parse both strings into variables such as sClassA and sClassB.
You can run the script in a way that it reproduces both conditions and create parsing functions whilst using the try script truelog.
The variables which are not an empty strings are the ones that exist.
0 Likes
Highlighted
Absent Member.
Absent Member.
tried something like below but seems not working:
BrowserClick("//div[@class='classA']|//p[@class='cassB']", BUTTON_Left, "either classA or classB");

BrowserVerifyProperty("//div[@class='classA']", "class", "classA");
This will return false and stop the scrip when it failed (while the p element could be present).
0 Likes
Highlighted
Micro Focus Frequent Contributor
Micro Focus Frequent Contributor
Since you say one of the two elements must exist then the solution is easy. Find just one of the two elements, if it exists then click it, if it doesnt exist then the other must so click the other. Pseudocode:

if (BrowserFind(HANDLE_DESKTOP, "//div[@class='classA']", false, 3000, true) = HANDLE_INVALID) then
BrowserClick("//div[@class='classB']|, BUTTON_Left, "classB"); // A doesn't exist so B must exist so click B
else
BrowserClick("//div[@class='classA']|, BUTTON_Left, "classB"); // A does exist so click it.
end;

View solution in original post

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.