✔ XPath text() vs dot (.) - text() Does Not Locate All Elements | (Video 48)

Published: 25 July 2019
on channel: Rex Jones II
3,448
58

Why XPath text() function does not locate some elements?
The text() function is designed to locate elements in a text node which are elements within double quotes. However, the text node must have a direct relationship with the element. This videos shows the difference between XPath text() and dot(.). Dot locates elements whether they’re in a text node or not.

► Download Cheat Sheet, Transcript, and Presentation https://test4success.lpages.co/select...
► Documentation via GitHub https://github.com/RexJonesII/Seleniu...

► All Videos On LinkedIn   / admin  
► All Videos On YouTube    / @rexjonesii  
► All Videos On Facebook https://www.facebook.com/pg/Selenium-...

► 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

► Transcript
Hello and Welcome To Selenium 4 Beginners. This video is a spin off from the XPath Function video Number 44. In that video we looked at dynamic values. The XPath text function and dot located a value that changed in the DOM. However, I mentioned there is a difference between the text function and dot.

We are going to look at the difference both XPath concepts using this presentation then a demo of Google. In this example, we want to find success. First, we locate class Search-Results then try to locate success. Notice, success is between the em tags. Em stands for emphasis which bold-face words on a web page. In order to find success, we would not use the text() function but use the dot (.).

The text() function will not find success because the text() function locates content in a text node. A text node only contains a string and strings are located inside quotes. Therefore, “The price of” and “is hard work, commitment, and dedication” are text nodes.
As a result in Example 2, the text() function will locate Success. We see Success is located in the text node. The third example is kind of tricky. Success is located inside in a text node but it does not have a direct relationship to the element.

What is the element? The element is div class = Search Results. Therefore, the text() function will not find success in the 2nd text node. On the other hand, the dot (.) for XPath will find success in all 3 examples. Now, let’s go to Chrome for our demo.

Search for Selenium Automation and inspect the description. We see Tag Name is span and class is st. Write 2 forward slashes, span, 2 brackets, contains, parenthesis, at, class, comma, 2 single quotes, st. Let’s try out a few things to see the difference between dot and text. Starting with dot, I’m going to write, 2 brackets, contains, 2 parenthesis, dot, comma, 2 single quotes, and search for Selenium. There are 6 results. Search all 6.

In each 1 of these results, Selenium is located within the em tag. The web page shows Selenium bold faced. Change the dot to text(). As expected, the text() function returns no results. Change Selenium to Test and there are 2 results. Search. Test is part of Testing and it is located in the first text node directly related to the element with a span tag and class containing ‘st’. Change the text() function to dot and we see 3 results. The text() function did not find Test for this search because it is located in the 1, 2, 3: 3rd text node for HP Quick Test Pro.

That’s it for the difference between XPath text() function and dot (.). You can download the presentation and transcript on github at RexJonesII/Selenium4Beginners or https://tinyurl.com/SeleniumLocatorsF...

#SeleniumTraining #SeleniumAutomation #BeginnerSeleniumTutorials #SeleniumWebDriver


Watch video ✔ XPath text() vs dot (.) - text() Does Not Locate All Elements | (Video 48) online without registration, duration hours minute second in high quality. This video was added by user Rex Jones II 25 July 2019, don't forget to share it with your friends and acquaintances, it has been viewed on our site 3,448 once and liked it 58 people.