Friday, October 19, 2018

XPath Using 'and'

'and' expression uses two conditions and both conditions must be true to locate a web element. It will fail to locate an element if any of the conditions is false.

Following explanation of  'and' expression will help us to understand this topic briefly.

Two conditions with 'and' expression such as A and B returns the result-set shown below:

A
B
Result
False
False
False
True
False
False
False
True
False
True
True
True

Syntax:
//tag[@attribute='value' and @attribute='value']
Example:
//div[@class='form-group' and @id='user-message']
Let's get a clear view with the below example:

When Condition One and Condition Two both are False then no result is found:
//div[@class = 'spch_' and @id = 'spch_']

When Condition One is False and Condition Two is True then no result is found:
//div[@class = 'spch_' and @id = 'spchc']

When Condition One is True and Condition Two is False then no result is found:
//div[@class = 'spchc' and @id = 'spch_']

When Condition One and Condition Two both are True then result is found:
//div[@class = 'spchc' and @id = 'spchc']

No comments:

Post a Comment