Tips & Tricks

Element Locators:

           Here are some of the easiest way with element locators to select web element I would like to share, if you didn't go thorough the sections Element Locators already I suggest to see once.
              Apparently, we need to find so many web elements to do some actions on it in our tests, and it also possible that an attribute includes space in it, so to remove such spaces we can use the following methods

             for example: I have a tag like this, <div data-jiis="bp" id="cnt" class="  mdm">...</div> 

if we want to select this 'div' tag using 'class' attribute then in
              X-Path:                //div[normalize-space(@class)='mdm'] should work, and in
CSS-Selector: div[class$='mdm']; will work. DOM: document.getElementsByClassName(' mdm') In X-path, we have a method called normalize-space(string) will remove the space at beginning and at end from the string. Css-selector div[class$='mdm'] searches the div tag that has class attributes which ends with string mdm The more we practice with these scenarios the better we do and the easiest way and most of the tools we have already available. The one such tool is chrome browser, to practice these methods. To open in chrome follow the steps 1)Open chrome browser, and launch any web site, for example, https://www.google.com 2)Enter any search word (Selenium software). Now press F12 (function key 12) on your keyboard, 3)Finally, press Esc (escape) key on your keyboard, this brings you console

On the console, if you want to test the above query mentioned in X-Path you have type between $x(""), i.e., it looks like $x("//div[normalize-space(@class)='mdm']"), and in CSS-selector $$(""), i.e,. it looks like $$("div[class$='mdm']"), and in DOM you have write as it is.

          There are other tools also available, to find element locators in different browsers for fire-fox we have bugzilla  or DOM Inspector and for Internet Explore it is IE WebDeveloper. We may find many other tools like such, but its depend on our own interest, we have to choose one. 

Q) How to debug element locators in IE..??

A) We need to install developer tool, and by default IE from version 7 it is available with in browser and to enable it use F12 key. After which to find an element using css locator then type the following code, for example 
document.querySelector("a[name='overridelink']")
   The result would be display as follows,

>> document.querySelector("a[name='overridelink']")http://localhost/index.do{
  charset : "",
  coords : "",
  hash : "",
  host : "localhost",
  hostname : "localhost",
  href : "http://localhost/index.do",
  hreflang : "",
  name : "overridelink",
  pathname : "/index.do"
  port : "80"
  ...
}
Add to watch

Quick Popup Question


Q) When to use Server jar files and Server stand alone jar..??

A) i) The standalone-server Jar is used to start a remote Node server or Grid 2 server. Some people start the server from their own code, but that is really the only time you would use that jar in your program.
ii) The Selenium Java Jar file is if you want to run WebDriver directly, or as a client using RemoteWebDriver talking to a Node or Grid 2 server. This is the jar you will definitely be using for writing your Web Driver code.
Firefox Setup while Handling SSL Certificate:

Q) How to see which firefox browser profile is currently using..??
A) In Firefox browser, navigate to Help -> Troubleshooting Information
We should see a subheading with name 'Application Basics' in bold and there we go..
Find a button "Show Folder" right adjacent to 'Profile Folder'

Q) How to suppress the saveAs dialog in selenium webdriver..??
A) Well, this can be achieved once after the firefox profile is set properly as explained here. Then once firefox profile instance available the set the preferences as follows

ffProfile.setPreference("browser.helpApps.neverAsks.openFile", "application/jar");
        this browser.helpApps.neverAsks.openFile accepts comma-separated list of MIME types to open directly without asking for confirmation. Default value is an empty string. find doc here

Q) How to get the inner text value of an element.?
      <title id="demo">Tutorial </title>

 A) There are 4 ways to get the value ('Tutorial') in java script.
      #1: document.getElementById('demo').innerHTML === 'Tutorial'
      #2: document.getElementById('demo').firstChild.nodeValue === 'Tutorial' //Note:case-senstive
      #3: document.getElementById('demo').innerText === 'Tutorial'
      #4: document.getElementById('demo').textContent === 'Tutorial'

       All of the above should return value, 'true'

     Pit falls:
      document.getElementById('demo').text === 'Tutorial'
      document.getElementById('demo').value=== 'Tutorial'
 
      These above return value is 'false'.


No comments:

Post a Comment