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
  • Pega testing training
    PEGA Testing Training
  • Today application testing is the deciding factor to launch the application into the market. And people do not launch the application unless it goes true.

  • blockchain course
    Blockchain Online Course
  • Today many people were enthusiastic, to know the exact details of things happening around him. This can get the proper knowledge on Blockchain.

  • ethical hacking course
    Ethical Hacking Certification Course
  • Zeal to learn ethical hacking is common among college students and IT professionals. Because everybody wants to secure their system from cyber attacks.

  • python training
    Python Online Training
  • Python is a dynamic interrupted language which is used in wide varieties of applications. It is very interactive object oriented and high-level programming language.

  • Tableau Training
    Tableau Training
  • Tableau is a Software company that caters interactive data visualization products that provide Business Intelligence services. The company’s Head Quarters is in Seattle, USA.

  • what is pega
    PEGA Online Training
  • Pega Systems Inc. is a Cambridge, Massachusetts based Software Company. It is known for developing software for Customer Relationship Management (CRM) and Business process Management (BPM).


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