We are using getTitle() method very frequently in out selenium webdriver tests. It is one of the basic and most commonly used method. getTitle() method is used to get the title of currently loaded web page. Also it will strip leading and trailing white space from title if available. Also it can return null if title of the page is not present.

Selenium WebDriver have many different methods and one of them is getCurrentUrl() method. So what is the actual usage of getCurrentUrl() method and when to use it. Well, any one can get a clue about usage of getCurrentUrl() method from its name. It will simply return current URL of browser after loading the page.

Web API
API (an application programming interface) is set of  rules, protocols, specifications and tools which allows two software programs to communicate with each other for developing software and application. It provides interface to communicate two different software programs to interact with each other if both follows API's protocols and rules. API is not user interface but it provides software to software interaction.

If you will do X thing by following rules of API, Y thing will happen. If you still not understand it then let me describe API with very simple example. 

I wants to TURN ON my TV which is operated by 230V AC current and 3 pins plug shape. Now supposing i have 4 different plugs as bellow.
  1. 2 Pins 120V AC
  2. 3 Pins 120V AC
  3. 2 Pins 230V AC
  4. 3 Pins 230V AC

Earlier we learnt about how to find XPath or CSS selector using Chrome Devtool to use it in selenium webdriver. ChroPath have same function with few additional feature which makes it more popular in selenium webdriver universe. Here i am presenting step by step guide to retrieve XPath or CSS selector of any web element using ChroPath chrome extension. Also we will look at few more useful features of ChroPath.

You can use SelectorsHub to Find XPath and CSS Selector.

Install ChroPath in Chrome
Before learning usage, You need to Install ChroPath in your chrome browser if it is not already installed. After Installation, Refresh your web page and it is ready to use now.

Finding XPath or CSS selector is very crucial task for selenium webdriver test script preparation and so google chrome has made it very easy for all and specially selenium users. There are many different chrome extensions available which provides this feature. But Google chrome's inbuilt Chrome Devtool is very easy to use. It has many other features as well but we will look at only XPath and CSS selector finder for now. Let's look it step by step.

Finding XPath/CSS selector of web element in chrome

Step 1 : First of all, Open your web page in google chrome browser. I will use http://only-testing-blog.blogspot.com/2014/01/textbox.html for this example. Here, we are going to find XPath and CSS selector of radio button with label Male.

Finding XPath of web element in chrome

Normalize-space is very useful function in XPath when you build it with reference of some string or keyword to use it webdriver script and it has leading or trailing intermediate repeating white space. Normalize-space will strip such unwanted space or white space. In selenium webdriver, very often we use keywords reference in building xpath. If there is not any good reference to build xapth then it is mandatory to use such keywords as reference.

You can look at my post describing different ways to build xpath .

Here i am presenting one example where we will use normalize-space function to build xpath and use it in selenium webdriver test script.

WebDriver interface has many different methods and get method is one of them. WebDriver interface is implemented by different browser classes like ChromeDriver, EdgeDriver, EventFiringWebDriver, FirefoxDriver, InternetExplorerDriver, OperaDriver, RemoteWebDriver and SafariDriver. So you can use get method to open any of these browser with given URL syntax.

get Method
  • Method Name : get
  • Method description : Using HTTP GET operation, It will load new web page in current web browser window. It will block all other operations until the browser load is completed. That means, Next syntax will be executed only after browser loaded completely with given URL.
  • Syntax : driver.get(String arg0)
  • Example : driver.get("http://www.google.com");

So in last article we have seen how to locate the WebElement using four locators and those are Name, Id, Partial Link Text and Link Text. Now in this article we are going to see the remaining four locators. Let’s start looking at them one by one.

Locating element By Xpath:
Xpath functions are very useful functions, it help to identify the Elements from its root node as well as from anywhere in the page. As HTML can be an execution of XML (XHTML), Selenium clients can use this amazing language to target WebElement in their web applications. XPath goes beyond (and additionally supporting) the straightforward techniques for situating by id or name attributes, and opens up a wide range of new conceivable outcomes, for example, finding the third checkbox on the page.