Access Modifiers in Java


We always use Public, Private, Protected in our Selenium scripts. Before using these, we should know how and where to use these access modifiers. Here is the table showing where we can call these modifiers:

Access Modifier
within class
within package
outside package by 
subclass only
outside 
package
Private
Y
N
N
N
Default
Y
Y
N
N
Protected
Y
Y
Y
N
Public
Y
Y
Y
Y


Basic Selenium Commands


Below are some basic commands of selenium which you can try and use while writing your script for automation of any website. If you face any problem, you can raise your query by completing the form available at Contact Us page:

  1. driver.get("http://www.google.com"); To open an application
  2. driver.findElement(By.id("passwd-id")); Finding Element using Id
  3. driver.findElement(By.name("passwd")); Finding Element using Name
  4. driver.findElement(By.xpath("//input[@id=’passwd-id’]")); Finding Element using Xpath
  5. element.sendKeys("some text"); To type some data
  6. element.clear(); clear thecontents of a text field or textarea
  7. driver.findElement(By.xpath("//select")); Selecting the value
  8. select.findElements(By.tagName("option")); Selecting the value
  9. select.deselectAll(); This will deselect all OPTIONs from the first SELECT on the page
  10. select.selectByVisibleText("Edam"); select the OPTION withthe displayed text of “Edam”
  11. findElement(By.id("submit")).click(); To click on Any button/Link
  12. driver.switchTo().window("windowName"); Moving from one window to another window
  13. driver.switchTo().frame("frameName"); swing from frame to frame (or into iframes)
  14. driver.switchTo().frame("frameName.0.child"); to access subframes by separating the path with a dot, and you can specify the frame by itsindex too.
  15. driver.switchTo().alert(); Handling Alerts
  16. driver.navigate().to("http://www.example.com"); To Navigate Paeticular URL
  17. driver.navigate().forward(); To Navigate Forward
  18. driver.navigate().back(); To Navigate Backword
  19. driver.close(); Closes the current window
  20. driver.quit(); Quits the driver and closes every associated window.
  21. driver.switch_to_alert(); Switches focus to an alert on the page.
  22. driver.refresh(); Refreshes the current page.
  23. webdriver.manage().window().setPosition(new Point(-2000, 0); to minimize browser window

How to setup Classpath for Java in Windows 7?



We all know the importance of CLASSPATH for Java. Setting PATH/CLASSPATH is very easy if we have the correct steps. I've listed down the steps which will help you to set CLASSPATH/PATH for Java:
 
Step 1: Download Java or JDK from the following URL according to your computer configuration:
Step 2: Install it by click on setup.exe and following the steps.
Step 3: By default JDK installs at "C:\Program Files\Java\jdkxxx.xx" location only. Unless we change the location at the time of installation.
Step 4: Go to JDK installed location, open bin folder available at the location. Now, copy the path.
Step 5: Right-click on My Computer icon available at your desktop and select Properties.
Step 6: Now, click on Advanced System Settings and click on Advanced tab from the dialog box opened
Step 7: Click on Environment Variables and then System Variables.

Step 8: Edit path and add the copied bin (which we did in Step 4) in that. Below are some images to help you:



Step 9: Click on OK of Environment Variables window and System Properties window.
Step 10: To verify whether Classpath or path of java is set up correctly or not.

Open Command Prompt and enter java -version. You'll find a statement like mentioned below:

java version "1.7.0_45"
Java(TM) SE Runtime Environment (build 1.7.0_45-b18)

Prerequisites to Start Learning Selenium Webdriver


You will need the following to start using Selenium WebDriver or in other words you can say prerequisites required to setup Selenium Webdriver??


  • Java Development Kit (JDK) ( To download it, click here)
  • Eclipse IDE - (To download it, click here)
  • Jar Files (Java Client Driver) - (To download it, click here)

What is HTMLUnitDriver?


HTMLUnitDriver is fastest (50% faster than Firefox), lightweight, platform independent. However, we don't use it. We always prefer to use Firefox, Chrome, IE but not HTMLUnitDriver

Do you know why?? 

Here is the answer:

How to Login and Logout in Gmail

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Openbrowser
{
public static void main(String args[]) throws InterruptedException
{
WebDriver driver=new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS);
driver.get("http://gmail.com/");
driver.findElement(By.id("Email")).sendKeys("raghav@mobikwik.com");
driver.findElement(By.id("Passwd")).sendKeys("9910979218");
driver.findElement(By.id("signIn")).click();
Thread.sleep(4000);
driver.findElement(By.xpath("//*[@id='gb']/div[1]/div[1]/div[2]/div[5]/div[1]/a/span")).click();
driver.findElement(By.id("gb_71")).click();
}
}

Selenium Webdriver Commands


This is the key of Selenium Webdriver Commands. These are the most commands which will help you in writing your scripts. 


Selenium WebDriver Commands
Selenium Webdriver Commands

Chrome and Internet Explorer driver



Download 32 Bit Chrome Driver by clicking on below Download link:

DOWNLOAD

You can use 32 Bit Chrome Driver on 32 Bit as well as 64 Bit Windows. There is no 64-bit Chrome on Windows yet (See this ticket), as a result there is no ChromeDriver for 64-bit Windows.

Here 32/64 bit are in terms of browser's architecture, not the OS.

Download 64 Bit Internet Explorer Driver by clicking on below Download link:

DOWNLOAD