Selenium - must reads?
After many (17 or is it 18 ...really..??) years in testing I now got the taks of doing some test automation with Selenium.
I would like to know if you could recommend some must-reads for learning about Selenium?
Especially the part about locating those webelements is confussing me/giving me headache.
I supose others have had the same ...eeeh experience, so hoping someone has some good must-reads to share :-)
Thank you very much,
On the locating web elements, there are 3 essential skills that will help you that is outside of Selenium.
There are 2 main ways of locating web elements in general, XPath and CSS Selectors. Selenium gives you other selectors like 'name', 'tag', 'link_text', etc... But really XPath and CSS selectors are all you need, these 2 selectors are the selectors that Developers use to find elements. You might of seen JQuery code that reads like $('tagname.classname etc...'), or document.querySelector(), that is CSS at work. The 2nd is XPath, not so popular now, it's commonly used to navigate XML. I would learn to use those 2. Between those 2, you can select almost any element. (the exception is custom drawn canvas elements, or things inside plugins such as Flash or Silverlight)
The 2nd thing to learn about finding web elements is to learn to use Chrome, Safari, Firefox's developer tools menus, then simplifying the expression. They have ways to locate elements, and you can get the full CSS or Xpath of an element. But the trick is, those xpaths or CSS generated is volatile. You'll want to learn the art of simplifying your xpath or CSS selectors. Here's one I wrote about XPath, Engineering Quality: 3 Useful Techniques to shortening your xpath Here's an article that'll help you with CSS, Writing efficient CSS selectors ? CSS Wizardry ? CSS, OOCSS, front-end architecture, performance and more, by Harry Roberts
The 3rd concept is knowing the context where your element exists. For any given context, you'll have to learn how to switch selenium's context to that type. An element can exist in the following places:
- On the current DOM (no switching needed)
- Within a Frame or Iframe Element, you need to switch frame context.
- A popup window, you need to switch window context
- Within a context of a embedded native browser plugin, like Flash or embedded video player. (this is a hard case to deal with, requires bridging or some plugin/extension to selenium)
- Within a context a context of shadow dom (this is for more modern web frameworks like Polymer, not well supported by selenium yet, they almost operate like iframes, not seen mucn on production sites yet)
- Within a context of an overlay created by a browser extension, such as the Pintrist browser extension. handle by switching window context.
- As an image map, HTML map tag (this was how web GUIs were done a long time ago, almost extinct now), these have to be handled using hard coded coordinates.
I came from a QTP/UFT backround and it took a little bit to get used to. (I never studied JAVA either before starting Selenium) I use xpath for the vast majority of object identification. I like the developer tools in Chrome. I just point at an object and I can copy the xpath id.
Patience is like bread I say.... I ran out of that yesterday.
Thank you very much for your replies.
David, Thanks for very useful links :-)
@gencke, following post will suffice Java required to work with selenium,
Last edited by avashistha; 10-12-2016 at 09:17 PM.