Selenium Best Practices

1) Use Robust object identification methods: Preferred selector order: id > name >css>xpath To locate an element we can use • the element’s ID e.g- driver.findElement("LinkId")).click(); • the element’s name attribute e.g- driver.findElement("LinkName")).click(); • by CSS statement e.g- driver.findElement(By.cssSelector(“a#LinkId”)).click(); • the element’s CSS statement e.g- driver.findElement(By.css("LinkName")).click(); • an XPath statement e.g- driver.findElement(By.xpath([//div 2/a[text()=’LinkText’]")).click(); • by a links text e.

Data Driven script with WebDriver

Example Testcase: Create a script to check login functionality of Gmail. Steps followed: 1) Open Google. 2) Click on Sign in 3) Enter Username and Password. 4) Submit Creds. 5) Check if the user is Signed In Script: import; import; import; import; import java.util.concurrent.TimeUnit; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import; import; import; import org.junit.*; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver;

Webdriver Script basics with sample code

WebDriver Basic Syntax: 1. Creating New Instance of Firefox Driver: WebDriver driver = new FirefoxDriver(); //Above given syntax will create new instance of Firefox driver. 2. Command to Open URL In Browser: driver.get(""); //This syntax will open specified URL in web browser. 3. Clicking on any element or button of webpage: driver.findElement("submitButton")).click(); //Above given syntax will click on targeted element in WebDriver. 4. Store text of targeted element in variable: String dropdown = driver.findElement(By.tagName("select")).getText(); //This syntax will retrieve text from targeted

WebDriver Basics and Setup instructions

WebDriver Basics and Setup instructions A: What is WebDriver? • WebDriver is a web automation framework that allows us to execute our tests against different browsers, not just Firefox (unlike Selenium IDE). WebDriver supports Firefox, Chrome, IE, Safari and Opera. • WebDriver supports web as well mobile application testing so we can also test mobile applications (IPhone or Android). • WebDriver also enables us to use a programming language to create our test scripts (that is not possible in Selenium IDE). • We can now use conditional operations like if-then-else or switch-case. We can also perform looping like do-while. • Following programming languages are supported