Webdriver Operators

Browser Elements Operations :

Selenium supports different kinds of operations. So by adding packages to your project,  this tools allows you to perform various operations. So let us have looked over the various operations that the selenium tool can perform.

import org.openqa.selenium.WebDriver;

This is a library package that contains the required class to initiate the browser loaded with a specific driver.

import org.openqa.selenium.firefox.FirefoxDriver;

This library package contains the Firefox Driver Class. When the driver class initiated, this class starts the driver as a class.

System.setProperty(“webdriver.gecko.driver”, “files/geckodriver.exe”);

This command notifies the run time engine that the Gecko driver is present in the specified path. So to work with the web driver after Firefox 35, we need to download the Gecko driver.  Besides,  if you want to test it on chrome, you have to download on the chrome driver and specify its path in its line of code.  Moreover,  online courses added, this procedure is similar for other browsers too.

WebDriver driver = new FirefoxDriver();

This command is used to initiate the new FireFox driver object.

driver.get(“https://onlineitguru.com/”);

This method is used to open a Specified URL.

driver.getTitle(); –

This command gets the title tab that is currently open in the browser.

driver.quit();

This command closes the driver

navigate.to()

This is used to navigate to other URL and do testing.

navigate.back()

This is used to come back to the previous page.

navigate.refresh():

This is used to refresh the current page.

We can maximize the browser with the following code

driver.manage().window().maximize();

Today in this computerized world, we can find a person without the wallet, but we could not find people without mobile ( I hope asking you regarding the Facebook account is Stupid ! ) So let’s have a look regarding how to login the Facebook account through Code.

Visit www.facebook.com and right click in that area and select Inspect element and finally move to the Elements column. In that are you will be finding different options like E-mail/phone, Password, and log in.  And through code, you can add these fields in the following manner.

driver.findElement(By.name("email")).sendKeys("xxx@gmail.com");

driver.findElement(By.name("pass")).sendKeys("xxxxxx");

driver.findElement(By.id("u_0_q")).click();

So adding these line of code is not enough.  Because the dynamics of the page may (or) may not respond fastly. And if the page does not respond fastly, it throws a timeout exception error. And this issue does not happen on popular websites like Facebook. But this usually happens in e-commerce websites

So we need an alternative solution to this problem. Moreover, here we need to request the web driver to wait sometime when the page is accessed. And if the page load completely, we need to locate the elements and then perform the actions. So in this case, you want your web driver to wait until all the elements in the web page get loaded and then closes the browser. So in this case, you use the driver.wait() and thread.sleep ().  Moreover, this method allows you to wait for the specified amount of time by the user. 

The following code opens the Facebook ID and password ( Replace your credentials in your code)

Code:
package seleniumWebDriver;

import org.openqa.selenium.WebDriver;

//import firefox

import org.openqa.selenium.firefox.FirefoxDriver;

import java.util.concurrent.TimeUnit;

public class WebDriverClass

{

public static void main(String[] args)

{

System.setProperty("webdriver.gecko.driver", "files/geckodriver.exe");

WebDriver driver = new FirefoxDriver();

driver.get("https://www.facebook.com/");

driver.manage().window().maximize();

driver.getTitle();

driver.navigate().to(“https://www.edureka.co/testing-with-selenium-webdriver”);

driver.navigate().back();

driver.navigate().refresh();

driver.wait(5000);

// or use

// Thread.sleep(5000);

driver.findElement(By.name("email")).sendKeys("xxx@gmail.com");

driver.findElement(By.name("pass")).sendKeys("xxxxxx");

driver.findElement(By.id("u_0_q")).click();

driver.quit();

}

}

Also check How to integrate Selenium Webdriver with Cucumber

Subscribe
to our newsletter

Drop Us A Query

Trending Courses
  • Selenium with python
    Selenium with Python Training
  • As we know, that Selenium with Python Web Browser Selenium Automation is Gaining Popularity Day by Day. So many Frameworks and Tools Have arisen to get Services to Developers.

  • Deep learning course
    Deep Learning Course
  • Artificial Intelligence, Deep mastering (DL) is completely about, many levels of Representation and sort of abstraction. That guide to design a sense of Information like Images, sound and text format.

  • machine learning with python
    Machine Learning with Python Training
  • Over last few years, Big Data and analysis have come up, with Exponential and modified Direction of Business. That operate Python, emerged with a fast and strong Contender for going with Predictive Analysis.

  • Data science with R
    Data Science With R Training
  • Understanding and using Linear, non-linear regression Models and Classifying techniques for stats analysis. Hypothesis testing sample methods, to get business decisions.

  • data science with python
    Data Science with Python Training
  • Everyone starts Somewhere, first you learn basics of Every Scripting concept. Here you need complete Introduction to Data Science python libraries Concepts.

  • devops with azure
    Devops with Azure Training
  • As we Know Azure DevOps is a Bunch of Services, in guiding Developers. It contains CI/CD, pipelines, code Repositories, Visual Reporting Tools and more code management with version control.


100% Secure Payments. All major credit & debit cards accepted.