1.

What are the types of WebDriver APIs available in Selenium?

Answer»

Selenium Webdriver is itself an API and it’s an interface. Selenium hierarchy contains two WebDriver - Remote WebDriver and Selenium WebDriver. Remote WebDriver is a class that implements the Selenium WebDriver interface whereas browser classes ChromeDriver(), FirefoxDriver() and etc. extend the Remote WebDriver. There are many APIs and methods in Selenium and following are some as follows:

 1. Navigation Commands:

  • navigate().to(URL) - To navigate to a particular URL.

Driver.navigate().to("http://qatechhub.com");

  • get(url) - To navigate to a particular URL.

Driver.get("http://qatechhub.com");

  • navigate().BACK() - Takes us  back in the browsing

Driver.navigate().back();

  • navigate().forward() - Takes us  forward in the browsing

Driver.navigate().forward();

  • navigate().refresh() - reloads the page.

Driver.navigate().refresh();

2. Resizing Windows:

  • Set Size - Sets the size of the window; the unit used is pixels.
  • Dimension d = new Dimension(640, 640);
  • Driver.manage().window().setSize(d);
  • Maximizing the Window - To set the size of the window as full size as per the screen.
  • Driver.manage().window().maximize();

3. DELETING Cookies:

Delete cookies in Selenium as per below command

Driver.manage().deleteAllCookies();

This will not actually delete the physical cookies file from the browser but it bypasses these files that cookies don’t appear in the browsing experience.

4. Closing the Browser:

  • close() - Closes the active window
  • Driver.close();
  • quit() - closes all the windows which are open in Selenium sessions
  • Driver.quit();

5. Different Get Methods:

  • getCurrentUrl() - This method returns the URL of the currently active page as a string.
  • getPageSource() - This method returns the complete HTML source code of the page.
  • getTitle() - This method returns the title of the current page as a string.
  • getWindowHandle() - This method returns the sessionId or windowHandle as a string.
  • getWindowHandles() - This method returns a set of sessionIds or windowHandles.

6. Searching WebElements: 

To search for web elements on a web page below methods are used:

  • findElement() - This method returns a web element that matches the REQUIRED criteria.
WebElement element = Driver.findElement(By.id("text-box"));
  • findElements() - This method returns a LIST of web elements which match the criteria.
List<WebElement> allElements = Driver.findElements(By.id("checkbox"));

7. Mouse Operations:

Mouse operations like mouse HOVER, drag, and drop, right clickor double click with Selenium actions class is used:

Mouse Hover:      

Actions action = new Actions(Driver);

WebElement mobileElement = Driver.findElement(By.linkText("Mobile & Accessories")); action.moveToElement(mobileElement).build().perform();

Drag and Drop:

WebElement source = Driver.findElement(By.id("draggable")); WebElement target = Driver.findElement(By.id("droppable")); Actions action = new Actions(Driver); action.dragAndDrop(source, target).build().perform();


Discussion

No Comment Found