Sunday, April 19, 2015

Difference Between isElementPresent & isElementDisplayed - Selenium

Selenium Commands - isElementPresent & isElementDisplayed


isElementPresent will check if an Element is present on the page by returning the value as true or false.

isElementDisplayed will check if the element is displayed on the page or not, but IT SHOULD be available on the HTML Doc.


For Example, say if you are searching for an element by xpath which is basically incorrect. If you use isElementPresent method will return false, but if you use isElementDisplayed, the code will give an Error. 

Saturday, April 18, 2015

Handling menu & Sub-Menu’s in Selenium

Handling menu & Sub-Menu’s in Selenium Using Actions Class

In this Topic I am going to explain how we can navigate to Menus’ and SubMenus and perform actions using the Action Class.

Let us suppose, we want to click T-Shirts under the Mens Section on Flipkart.com, for that I have to do below steps:

  • Open Flipkart.com
  • Move the mouse to Men’s on Toolbar (Make note that we don’t click here, the submenu opens on hover automatically)
  • Click on T-Shirt

Event Firing Mouse – Selenium

Event Firing Mouse - Selenium


Here I am going to explain how to move the mouse using the Event Firing Mouse. One need to keep in mind that this does not move the mouse physically.

You can check the Mouse interface on Seleniumhq.org for more details .

Below are the methods which can be used with Mouse Interface

Mouse Interface - Methods


Event Listeners - Selenium WebDriver

Event Listeners:

Used when I want on Execution of a particular action/event a code should be executed. For E.g. , Say on Click of a click a piece of code should be executed.

This is included in Interface WebDriverEventListener which has the method bodies which can be used for such purpose. The class which implements this is AbstractWebDriverEventListener

Let us see the implementation of Listeners:

Step 1: Create a Class containing the methods to be used , say weblisteners where we can define the methods. Code is as below:
 
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.events.AbstractWebDriverEventListener;


public class weblisteners extends AbstractWebDriverEventListener {
      
       public void afterClickOn(WebElement element, WebDriver driver){
              System.out.println("Object Has been Clicked");
       }

}
 

Friday, April 17, 2015

Handling Firefox Profiles & Synchronization in Selenium

What is Profile – By profile, it is meant the default setting which your browser takes while opening the webpage. For Example in your profile you can save your Favorites, your default homepage and other settings.