Android apps to use in appium android test examples


Tuesday, March 13, 2018

Selenium WebDriver Tutorials - Basic Action Commands And Operations With Examples

I direct maintain already posted Selenium WebDrier Tutorials posts how to setup spider web driver alongside eclipse and Run starting fourth dimension show alongside webdriver, how to configure junit alongside eclipse to generate webdriver show report. We direct maintain also acquire dissimilar methods of locating elements of software spider web application in webdriver. All these things are really basic things in addition to yous quest to acquire all of them before starting your show instance creation inwards selenium 2. Now nosotros are laid to acquire adjacent pace of performing basic actions inwards spider web driver alongside coffee for your software spider web application.

Today I wants to pull yous few basic webdriver commands to perform actions on spider web chemical ingredient of your software spider web application's spider web page. We tin perform also many ascendence operations inwards webdriver to automate software application show procedure in addition to volition aspect virtually them 1 past times 1 inwards close future. Right directly I am describing yous few of them for your sort information. Bellow given commands are usually used commands of selenium webdriver to role inwards automation procedure of whatsoever software spider web application.

1. Creating New Instance Of Firefox Driver
WebDriver driver = novel FirefoxDriver();
Above given syntax volition practise novel instance of Firefox driver. VIEW PRACTICAL EXAMPLE

2. Command To Open URL In Browser
driver.get(" ");
This syntax volition opened upwardly specified URL of software spider web application inwards spider web browser. VIEW PRACTICAL EXAMPLE OF OPEN URL

3. Clicking on whatsoever chemical ingredient or push of webpage
Above given syntax volition click on targeted chemical ingredient inwards webdriver. VIEW PRACTICAL EXAMPLE OF CLICK ON ELEMENT

4. Store text of targeted chemical ingredient inwards variable
String dropdown = driver.findElement(By.tagName("select")).getText();
This syntax volition think text from targeted chemical ingredient of software spider web application page in addition to volition shop it inwards variable = dropdown. VIEW PRACTICAL EXAMPLE OF Get Text

5. Typing text inwards text box or text area.
driver.findElement("fname")).sendKeys("My First Name");
Above syntax volition type specified text inwards targeted element. VIEW PRACTICAL EXAMPLE OF SendKeys

6. Applying Implicit hold off inwards webdriver
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
This syntax volition forcefulness webdriver to hold off for fifteen 2nd if chemical ingredient non flora on page of software spider web application. VIEW PRACTICAL EXAMPLE OF IMPLICIT WAIT

7. Applying Explicit hold off inwards webdriver alongside WebDriver canned conditions.
WebDriverWait hold off = novel WebDriverWait(driver, 15); wait.until(ExpectedConditions.textToBePresentInElementLocated(By.xpath("//div[@id='timeLeft']"), "Time left: seven seconds"));
Above two syntax volition hold off for till fifteen seconds for expected text "Time left: seven seconds" to endure look on targeted element. VIWE DIFFERENT PRACTICAL EXAMPLES OF EXPLICIT WAIT

8. Get page championship inwards selenium webdriver
It volition think page championship in addition to yous tin shop it inwards variable to role inwards adjacent steps. VIEW PRACTICAL EXAMPLE OF GET TITLE

9. Get Current Page URL In Selenium WebDriver
It volition think electrical flow page URL in addition to yous tin role it to compare alongside your expected URL. VIEW PRACTICAL EXAMPLE OF GET CURRENT URL

10. Get domain cite using coffee script executor
JavascriptExecutor javascript = (JavascriptExecutor) driver; String CurrentURLUsingJS=(String)javascript.executeScript("return document.domain");
Above syntax volition think your software application's domain cite using webdriver's coffee script executor interface in addition to shop it inwards to variable. VIEW GET DOMAIN NAME PRACTICAL EXAMPLE.

11. Generate alarm using webdriver's coffee script executor interface
JavascriptExecutor javascript = (JavascriptExecutor) driver; javascript.executeScript("alert('Test Case Execution Is started Now..');");
It volition generate alarm during your selenium webdriver show instance execution. VIEW PRACTICAL EXAMPLE OF GENERATE ALERT USING SELENIUM WEBDRIVER.

12. Selecting or Deselecting value from driblet downwardly inwards selenium webdriver.
  • Select By Visible Text
Select mydrpdwn = novel Select(driver.findElement("Carlist"))); mydrpdwn.selectByVisibleText("Audi");
It volition direct value from driblet downwardly listing using visible text value = "Audi".
  • Select By Value
Select listbox = novel Select(driver.findElement(By.xpath("//select[@name='FromLB']"))); listbox.selectByValue("Italy");
It volition direct value past times value = "Italy".
  • Select By Index
Select listbox = novel Select(driver.findElement(By.xpath("//select[@name='FromLB']"))); listbox.selectByIndex(0);
It volition direct value past times index= 0(First option).


  • Deselect by Visible Text
Select listbox = novel Select(driver.findElement(By.xpath("//select[@name='FromLB']"))); listbox.deselectByVisibleText("Russia");
It volition deselect alternative past times visible text = Russian Federation from listing box.
  • Deselect by Value
Select listbox = novel Select(driver.findElement(By.xpath("//select[@name='FromLB']"))); listbox.deselectByValue("Mexico");
It volition deselect alternative past times value = United Mexican States from listing box.
  • Deselect by Index
Select listbox = novel Select(driver.findElement(By.xpath("//select[@name='FromLB']"))); listbox.deselectByIndex(5);
It volition deselect alternative past times Index = v from listing box.
  • Deselect All
Select listbox = novel Select(driver.findElement(By.xpath("//select[@name='FromLB']"))); listbox.deselectAll();
It volition take all selections from listing box of software application's page.


  • isMultiple()
Select listbox = novel Select(driver.findElement(By.xpath("//select[@name='FromLB']"))); boolean value = listbox.isMultiple();
It volition furnish truthful if direct box is multiselect else it volition furnish false.VIEW PRACTICAL EXAMPLE OF isMultiple()

13. Navigate to URL or Back or Forward inwards Selenium Webdriver
driver.navigate().to(" "); driver.navigate().back(); driver.navigate().forward();
1st ascendence volition navigate to specific URL, 2nd volition navigate 1 pace dorsum in addition to tertiary ascendence volition navigate 1 pace forward. VIEW PRACTICAL EXAMPLES OF NAVIGATION COMMANDS.

14. Verify Element Present inwards Selenium WebDriver
Boolean iselementpresent = driver.findElements(By.xpath("//input[@id='text2']")).size()!= 0;
It volition furnish truthful if chemical ingredient is acquaint on page, else it volition furnish faux inwards variable iselementpresent. VIEW PRACTICAL EXAMPLE OF VERIFY ELEMENT PRESENT.

15. Capturing entire page screenshot inwards Selenium WebDriver
File screenshot = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); FileUtils.copyFile(screenshot, novel File("D:\\screenshot.jpg"));
It volition capture page screenshot in addition to shop it inwards your D: drive. VIEW PRACTICAL EXAMPLE ON THIS PAGE.

16. Generating Mouse Hover Event In WebDriver
Actions actions = novel Actions(driver); WebElement moveonmenu = driver.findElement(By.xpath("//div[@id='menu1']/div")); actions.moveToElement(moveonmenu); actions.perform();
Above instance volition motility mouse on targeted element. VIEW PRACTICAL EXAMPLE OF MOUSE HOVER.

17. Handling Multiple Windows In Selenium WebDriver.
  1. Get All Window Handles.
  2. Set<String> AllWindowHandles = driver.getWindowHandles();
  3. Extract nurture in addition to youngster window handgrip from all window handles.
  4. String window1 = (String) AllWindowHandles.toArray()[0]; String window2 = (String) AllWindowHandles.toArray()[1];
  5. Use window handgrip to switch from 1 window to other window.
  6. driver.switchTo().window(window2);
Above given steps alongside helps yous to acquire window handgrip in addition to and then how to switch from 1 window to around other window. VIEW PRACTICAL EXAMPLE OF HANDLING MULTIPLE WINDOWS IN WEBDRIVER

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 volition verify that chemical ingredient (text box) fname is enabled or not. You tin role it for whatsoever input element. VIEW PRACTICAL EXAMPLE OF VERIFY ELEMENT IS ENABLED OR NOT.

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 volition disable fname chemical ingredient using setAttribute() method in addition to enable lname chemical ingredient using removeAttribute() method. VIEW PRACTICAL EXAMPLE OF ENABLE/DISABLE TEXTBOX.

20. Selenium WebDriver Assertions With TestNG Framework
  • assertEquals
Assert.assertEquals(actual, expected);
assertEquals assertion helps yous to assert actual in addition to expected equal values. VIEW PRACTICAL EXAMPLE OF assertEquals ASSERTION
  • assertNotEquals
Assert.assertNotEquals(actual, expected);
assertNotEquals assertion is useful to assert non equal values. VIEW PRACTICAL EXAMPLE OF assertNotEquals ASSERTION.
  • assertTrue
assertTrue assertion plant for boolean value truthful assertion. VIEW PRACTICAL EXAMPLE OF assertTrue ASSERTION.
  • assertFalse
assertFalse assertion plant for boolean value faux assertion. VIEW PRACTICAL EXAMPLE OF assertFalse ASSERTION.

21. Submit() method to submit form
It volition submit the form. VIEW PRACTICAL EXAMPLE OF SUBMIT FORM.

22. Handling Alert, Confirmation in addition to Prompts Popups

String myalert = driver.switchTo().alert().getText();



driver.switchTo().alert().sendKeys("This Is John");
To type text In text box of prompt popup. VIEW PRACTICAL EXAMPLE OF TYPE TEXT IN PROMPT TEXT BOX

More interesting articles here :Generation Enggelmundus Internet Marketing Tool here :Zeageat IM

No comments:

Post a Comment