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("http://only-testing-blog.blogspot.in/2013/11/new-test.html");
This syntax will open specified URL in web browser.
3. Clicking on any element or button of webpage
driver.findElement(By.id("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 element and will store it in variable = dropdown.
5. Typing text in text box or text area.
driver.findElement(By.name("fname")).sendKeys("My First Name");
Above syntax will type specified text in targeted element.
6. Applying Implicit wait in webdriver
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
This syntax will force webdriver to wait for 15 second if element not found on page.
7. Applying Explicit wait in webdriver with WebDriver canned conditions.
WebDriverWait wait = new WebDriverWait(driver, 15);
wait.until(ExpectedConditions.textToBePresentInElementLocated(By.xpath("//div[@id='timeLeft']"), "Time left: 7 seconds"));
Above 2 syntax will wait for till 15 seconds for expected text "Time left: 7 seconds" to be appear on targeted element.
8. Get page title in selenium webdriver
driver.getTitle();
It will retrieve page title and you can store it in variable to use in next steps.
9. Get Current Page URL In Selenium WebDriver
driver.getCurrentUrl();
It will retrieve current page URL and you can use it to compare with your expected URL.
10. Get domain name using java script executor
JavascriptExecutor javascript = (JavascriptExecutor) driver;
String CurrentURLUsingJS=(String)javascript.executeScript("return document.domain");
Above syntax will retrieve your software application's domain name using webdriver's java script executor interface and store it in to variable.
11. Generate alert using webdriver's java script executor interface
JavascriptExecutor javascript = (JavascriptExecutor) driver;
javascript.executeScript("alert('Test Case Execution Is started Now..');");
It will generate alert during your selenium webdriver test case execution.
12. Selecting or Deselecting value from drop down in selenium webdriver.
• Select By Visible Text
Select mydrpdwn = new Select(driver.findElement(By.id("Carlist")));
mydrpdwn.selectByVisibleText("Audi");
It will select value from drop down list using visible text value = "Audi".
• Select By Value
Select listbox = new Select(driver.findElement(By.xpath("//select[@name='FromLB']")));
listbox.selectByValue("Italy");
It will select value by value = "Italy".
• Select By Index
Select listbox = new Select(driver.findElement(By.xpath("//select[@name='FromLB']")));
listbox.selectByIndex(0);
It will select value by index= 0(First option).
Deselect by Visible Text
Select listbox = new Select(driver.findElement(By.xpath("//select[@name='FromLB']")));
listbox.deselectByVisibleText("Russia");
It will deselect option by visible text = Russia from list box.
• Deselect by Value
Select listbox = new Select(driver.findElement(By.xpath("//select[@name='FromLB']")));
listbox.deselectByValue("Mexico");
It will deselect option by value = Mexico from list box.
• Deselect by Index
Select listbox = new Select(driver.findElement(By.xpath("//select[@name='FromLB']")));
listbox.deselectByIndex(5);
It will deselect option by Index = 5 from list box.
• Deselect All
Select listbox = new Select(driver.findElement(By.xpath("//select[@name='FromLB']")));
listbox.deselectAll();
It will remove all selections from list box.
isMultiple()
Select listbox = new Select(driver.findElement(By.xpath("//select[@name='FromLB']")));
boolean value = listbox.isMultiple();
It will return true if select box is multiselect else it will return false.
13. Navigate to URL or Back or Forward in Selenium Webdriver
driver.navigate().to("http://only-testing-blog.blogspot.in/2014/01/textbox.html");
driver.navigate().back();
driver.navigate().forward();
1st command will navigate to specific URL, 2nd will navigate one step back and 3rd command will
14. Verify Element Present in Selenium WebDriver
Boolean iselementpresent = driver.findElements(By.xpath("//input[@id='text2']")).size()!= 0;
It will return true if element is present on page, else it will return false in variable iselementpresent.
15. Capturing entire page screenshot in Selenium WebDriver
File screenshot = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(screenshot, new File("D:\\screenshot.jpg"));
It will capture page screenshot and store it in your D: drive.
16. Generating Mouse Hover Event In WebDriver
Actions actions = new Actions(driver);
WebElement moveonmenu = driver.findElement(By.xpath("//div[@id='menu1']/div"));
actions.moveToElement(moveonmenu);
actions.perform();
Above example will move mouse on targeted element.
17. Handling Multiple Windows In Selenium WebDriver.
1. Get All Window Handles.
Set<String> AllWindowHandles = driver.getWindowHandles();
2. Extract parent and child window handle from all window handles.
String window1 = (String) AllWindowHandles.toArray()[0];
String window2 = (String) AllWindowHandles.toArray()[1];
3. Use window handle to switch from one window to other window.
driver.switchTo().window(window2);
Above given steps with helps you to get window handle and then how to switch from one window to another window
18. Check Whether Element is Enabled Or Disabled In Selenium Web driver.
boolean fname = driver.findElement(By.xpath("//input[@name='fname']")).isEnabled();
System.out.print(fname);
Above syntax will verify that element (text box) fname is enabled or not. You can use it for any input element.
19. Enable/Disable Textbox During Selenium Webdriver Test Case Execution.
JavascriptExecutor javascript = (JavascriptExecutor) driver;
String todisable = "document.getElementsByName('fname')[0].setAttribute('disabled', '');";
javascript.executeScript(todisable);
String toenable = "document.getElementsByName('lname')[0].removeAttribute('disabled');";
javascript.executeScript(toenable);
It will disable fname element using setAttribute() method and enable lname element using removeAttribute() method.
20. Selenium WebDriver Assertions With TestNG Framework
• assertEquals
Assert.assertEquals(actual, expected);
assertEquals assertion helps you to assert actual and expected equal values.
assertNotEquals
Assert.assertNotEquals(actual, expected);
assertNotEquals assertion is useful to assert not equal values.
• assertTrue
Assert.assertTrue(condition);
assertTrue assertion works for boolean value true assertion.
• assertFalse
Assert.assertFalse(condition);
Its very nice.. -thanks Praveen
ReplyDeleteHi....Very nice.
ReplyDeleteGive me Ur mail id
Thanks.
ReplyDeleteThis is really helpful
Great artical !!!Selenium Training in Chennai | Oracle Training in chennai
ReplyDeleteeverything ok . nice and good.
ReplyDeletebut one doubt. if IDE & Firebug is not recognizing the elements( text box , list box, button , etc) of the website , how to write/locate element/ selenium (Xpath & Css Selector) coding using HTML coding of the website. ?
gr8 work
ReplyDeleteGreat lists of commands. Thank you very much!! I will note it and shared with my friends. Selenium training in Chennai | Best Selenium training institute in Chennai
ReplyDelete"Great blog created by you. I read your blog, its best and useful information. You have done a great work. Super blogging and keep it up.php jobs in hyderabad.
ReplyDelete"
I read this blog You explained clearly, it's easy to understand everyone keep sharing..check this information for a knowledge on Devops Online Training
ReplyDeleteI have been searching for quite some time for information on this topic and no doubt your website saved my time and I got my desired information. Your post has been very helpful. Thanks.
ReplyDeleteSelenium Training in Chennai
JAVA Training in Chennai
Big Data Training in Chennai
Hadoop Training in Chennai
iOS Training in Chennai
Selenium Courses in Chennai
The blog which you have posted is very informative to us. Thanks for your information sharing with us.
ReplyDeleteBest JAVA Training Institute in Coimbatore
JAVA Certification Course in Coimbatore
JAVA Training Institute in Coimbatore
JAVA Training Center in Coimbatore
JAVA Training
This information is impressive. I am inspired with your post writing style & how continuously you describe this topic. Eagerly waiting for your new blog keep doing more.
ReplyDeleteFranchise Business in India
Education Franchise
Computer Education Franchise
Education Franchise India
Computer Center Franchise
Education Franchise Opportunities in India
Franchise For Spoken English Classes
Computer Training Institute Franchise
English Language School Franchise
Best Education Franchise In India
The information which you have shared is more informative to us. Thanks for your blog.
ReplyDeletePHP Training in Coimbatore
Best PHP Training in Coimbatore
PHP Course in Coimbatore
Best PHP Training Institute in Coimbatore
PHP Training Center in Coimbatore
Nice way of expressing your ideas with us.thanks for sharing with us and please add more information's.
ReplyDeleteandroid coaching in bangalore
Android Training in Thirumangalam
Android Training in Amjikarai
Android Training in Padur
This was a helpful to me thanks for sharing these useful information. Kindly continue the work.
ReplyDeleteSpoken English Classes in Chennai | Spoken English Classes in OMR Chennai | Spoken English Classes in Navalur | Spoken English Classes near Thoraipakkam | Spoken English Classes in Sholinganallur | Spoken English Classes in Padur | Best Spoken English Classes in Chennai
This comment has been removed by the author.
ReplyDeleteThanks for sharing this useful commands, it is really helpful. Keep sharing more like this.
ReplyDeleteBlue Prism Training in Chennai
Blue Prism Training Institute in Chennai
Blue Prism course in Chennai
RPA Training in Chennai
UiPath Training in Chennai
AWS Training in Chennai
Angularjs Training in Chennai
Awesome Post. Thanks for Sharing. Kepp updating.
ReplyDeleteTableau Training in Tambaram
Tableau Courses in Tambaram
Tableau Training in Adyar
Tableau Courses in Adyar
It is really an awesome post. Keep sharing this kind of worthy information.
ReplyDeleteMobile Testing Course in Chennai | Mobile Testing Training in Chennai | Mobile Automation Testing Training in Chennai |
Mobile Testing Course in Adyar | Mobile Testing Training in Velachery | Mobile Testing Training in Tambaram
This comment has been removed by the author.
ReplyDeleteenglish to malayalam typing
ReplyDeletevery useful information
ReplyDeleteMicrosoft Windows Azure Training | Online Course | Certification in chennai | Microsoft Windows Azure Training | Online Course | Certification in bangalore | Microsoft Windows Azure Training | Online Course | Certification in hyderabad | Microsoft Windows Azure Training | Online Course | Certification in pune