Keys To XPath Conditions & Indexes For Selenium
XPath has conditions inside its square brackets that searches for an AttributeName and AttributeValue. The syntax is //TagName[@AttributeName='AttributeValue']. Multiple conditions are considered a Logical AND Condition. It is a Logical AND Condition because more than 1 AttributeName must equal the AttributeValue. The condition can be written with multiple brackets or with the keyword ‘and’.
A Logical OR Condition uses the keyword ‘or’. At least 1 of the conditions must match to return an element. XPath Indexes are helpful if our desired element is not the first element underneath a parent.
► Download Cheat Sheet, Transcript, and Presentation https://test4success.lpages.co/select...
► Documentation via GitHub https://github.com/RexJonesII/Seleniu...
Free Selenium Book covers XPath (pages 67 - 78)
► Free Selenium PDF Book: https://www.rexjones2.com/book-seleni...
► Free Java PDF Book: https://www.rexjones2.com/book-part-1...
► All Paperback & eBooks: http://tinyurl.com/Rex-Allen-Jones-Books
► View All Videos On LinkedIn / admin
► View All Videos On YouTube / @rexjonesii
► View All Videos On Facebook https://www.facebook.com/pg/Selenium-...
► Transcript
The next syntax is an illustration of 2 or more Attribute Names and Values. This syntax operates like the Logical AND Operator using 2 or more conditions. Let’s inspect the Excellent radio button.
According to the Selenium Locator rankings, we would use id or name before using XPath. However, here’s the power of XPath. Let’s imagine the application is under construction and the architect wants to make sure these Attribute Values do not change.
We find the element by using multiple attributes and if it breaks we know 1 or both values changed. 2 forward slashes, TagName input, square brackets, at symbol, Attribute Name id, equal, 2 single quotes then the Attribute Value pollanswers hyphen 1. We found the element but let’s add the square brackets again, at, name, equal, 2 single quotes then pollanswers hyphen 1. Success
The next syntax is the AND operator. It’s our preference, we can use the AND operator or multiple sets of brackets. All we do is replace the inside brackets with and. We still have our element with 1 of 1. Both syntaxes operate the same.
The next syntax is the OR operator. Change AND to OR but now we have 1 of 4. Search, Search, Search Why is that? That’s because all 4 radio buttons have the same value for name: pollanswers hyphen 1
Let’s inspect Search Store. This is a different scenario, imagine the architect is okay with one of the Attribute Values changing but we still want to find this element. We replace id with small-searchterms and name with q. Now, we see 1 of 1.
There are times when we have to use indexes to find our element. The next syntax has an index for TagName. We are going to switch AUT’s and look at Tables using W3 Schools. Inspect Helen Bennett. It’s best to write this XPath by starting with an attribute within the table tag. Table is the parent element for tbody, tr, and td. tbody describes the table body, tr is table row, and td is data in a particular cell.
2 forward slashes, TagName table, square brackets, at, Attribute Name id, equal, 2 single quotes then the Attribute Value is customers. One forward slash after the bracket which provides access to the child element tbody. Which row is Helen Bennet? 1, 2, 3, 4, 5. We write forward slash tr[5]. Helen Bennet is the 2nd cell for row 5. We write forward slash td[2]. The green background indicates we successfully found Helen Bennet.
You can find this Cheat Sheet at https://tinyurl.com/SeleniumLocatorsF... and github at RexJonesII/Selenium4Beginners.
Next, is XPath Functions.
► Free Java PDF Book: http://tinyurl.com/Part-1-Java-4-Sele...
► All Paperback & eBooks: http://tinyurl.com/Rex-Allen-Jones-Books
#SeleniumTraining #SeleniumAutomation #BeginnerSeleniumTutorials #SeleniumWebDriver
Смотрите видео ✔ Keys To XPath Conditions & Indexes For Selenium | (Video 43) онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь Rex Jones II 21 Июнь 2019, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 1,466 раз и оно понравилось 22 людям.