Selenium with Java
- By
- April 20, 2024
Java is one of the enterprised programming languages around the world. Syntactically not too simple, yet powerful because of its features.
So, learning Selenium in combination with java is never a bad choice.
Why Java with Selenium?
A)As Java is popular in the current era, learning Selenium with Java is a very good decision to start your career as an Automation Test Engineer. There is no wastage of time spent learning Java.
What are Web Applications?
Applications that basically run on the browser are called Web applications.
Ex: Facebook, Amazon, Flipkart, Instagram, and many more
Now let’s see how to install Java!!!
Go to the oracle website and download JDK(Java development Kit)
For Free, Demo classes Call: 8237077325
Registration Link: Click Here!
Visit the website selenium.dev
Now let’s see some of the most popular and frequently used methods in our Selenium Scripts:
Creating an object for the ChromeDriver class will launch the Chrome Browser from your system.
Ex:ChromeDriver driver = new ChromeDriver();
get() = This method is used to navigate to any website
Ex: driver.get(“https://www.facebook.com”)
quit() = This method is used to quit the Browser
Ex: driver. quit()
closee() = This method is used to closee the current tab on your browser.
Ex: driver.close()
getCurrentUrl() = This method is used to get the URL associated with that particular webpage.
Ex: driver.getCurrentUrl()
getTitle() = This method is used to get the Title associated with that webpage.
Ex: driver.getTitle()
sendKeys() = This method is used to enter the data into an input box.
Ex: driver.send_keys(“Welcome123”)
click() = This method is used to click on a particular button available on the webpage.
Ex: input.click()
clear() = This method is used to clear the data available in the input box.
Ex: input.clear()
For Free, Demo classes Call: 8237077325
Registration Link: Click Here!
Q)What are the various get methods available in selenium?
A)There are 3 commonly used get methods like getText(), getTagName(), getPageSource().
Q)What are the various boolean methods in selenium?
A) The various boolean methods are isDisplayed(), isEnabled() and isSelected().
Q)What are the various tools in Selenium?
A) The four tools available in selenium are Selenium IDE(Integrated Development Environment), Selenium RC(Remote Control), Selenium Grid and Selenium WebDriver.
Q)What are the two types of waits normally used in Selenium?
A) The two types of waits are Implicit Wait and Explicit Wait.
Q)What is Implicit Wait and Explicit Wait?
A) Implicit wait is a wait that is basically applied on the webpages but Explicit wait is applied for a Web Element present in the particular web page.
Q)What are the various frameworks available in selenium?
Q)What are the various popups that selenium can handle?
A) Alert Box Popup, Prompt Box Popup and Confirm Box Popup.
Q)What is the difference between findElement and findElements method?
A) Find element method will identify only one element on the webpage, but find elements method is used to identify multiple elements from the webpage.
Q)What are Frameworks?
A) Frameworks are nothing but rules (or) guidelines that can be used by the automation test engineer in selenium script to achieve 100% efficiency.
Locators:
Now let’s see what role locators play in selenium!
If Selenium wants to perform any kind of action on any of the webelements like Entering the text in an input box which is created using input tag, click on a button, getting the relevant information, selecting the drop-down from the webpage , click on refresh button, and many more, first selenium has to get the power to identify that web element, once the element is identified then selenium can easily perform the action on that web element. So, to identify that particular element for selenium
We use the concept of locators.
Various locators available in Selenium are:
We can identify the various web elements available on the webpage using the following locators:
Id: Which uses findElement(By.id()) method.
Name: which used findElement(By.name()) method.
className: which uses findElement(By.className()) method.
Tag Name: which used findElement(By.tagName()) method.
Link text: which uses findElement(By.linkText()) method.
Partial link text: which uses findElement(By.partialLinkText()) method.
Xpath: which uses findElement(By.xpath()) method.
CSS Selector: which uses findElement(By.css()) method.
NOTE: All the above locators are used to identify only one element at a time.
For Free, Demo classes Call: 8237077325
Registration Link: Click Here!
If we want to identify multiple elements, instead of using findElement we have to use findElements, and the rest of everything will be the same.
© Copyright 2021 | Sevenmentor Pvt Ltd.
COPYRIGHT © 2022 SevenMentor Pvt. Ltd | All Rights Reserved.