Global – Selenium Interview Questions
Here is the list of Selenium Interview Questions which are recently asked in Global company. These questions are included for both Freshers and Experienced professionals. Our Selenium Training has Answered all the below Questions.
1. Declared the method using final, How do I need to call the method?
class ChessAlgorithm {
enum ChessPlayer { White, black }
...
final ChessPlayer getFirstPlayer() {
return ChessPlayer.white;
}
...
}
2. What is abstract class,what is the use?
The abstract keyword is used to declare the class is called abstract class. It contains abstract menthod and concrete methods. A normal class cannot have abstract methods.
Abstract classes cannot be instantiated and are designed to be subclassed. They are used to provide some common functionality across a set of related classes while also allowing default method implementations.
3. What type of parameterization did you use in your project?
Types of Parameterization in TestNG- Using “Parameters annotation” and TestNG XML file.
- Using “DataProvider annotation”.
4. How to read data from database?
There are also two variants of the getBlob()method to read data from database.
Blob getBlob(int columnIndex)
Blob getBlob(String columnLabel)
5. What is webdrive?
WebDriver drives a browser natively, as a user would, either locally or on a remote machine using the Selenium server, marks a leap forward in terms of browser automation.
Selenium WebDriver refers to both the language bindings and the implementations of the individual browser controlling code. This is commonly referred to as just WebDriver.
6. How do you achieve synchronization in WebDriver?
The two or more components involved to perform any action is called Synchronization . we expect these components to work together with the same pace. The co-ordination between these components to run parallel is called Synchronization.
7. What is Selenium Grid?
Selenium Grid is a main part of the Selenium this allows in running multiple tests across different browsers, operating systems, and machines in parallel.
On the other hand, selenium Grid is achieved by routing the commands of remote browser instances where a server acts as a hub. A user needs to configure the remote server in order to execute the tests.
8. What is the use of deselect All () method?
Uses:
To remove selection from all selected options of select box.
Clears all selected entries, but it is only valid when the SELECT supports multiple selections.
Syntax:
Select listbox = new Select(driver.findElement(By.xpath("//select[@name='FromLB']")));
listbox.deselectAll();
9. How to hover the mouse on an element?
We can use the below three important steps for hover the mouse on an element.- With the help of Class
- moveToElement () method of the Actions class.
- build().perform()
Below code for your reference,
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Action;
import org.openqa.selenium.interactions.Actions;
import java.util.concurrent.TimeUnit;
public class MouseOver{
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "C:\\Users\\credosystemz\\Desktop\\Java\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
String url = " https://www.credosystemz.com/";
driver.get(url);
driver.manage().timeouts().implicitlyWait(12, TimeUnit.SECONDS);
// actions class with moveToElement() method for mouse hover to element
Actions a = new Actions(driver);
a.moveToElement(driver.findElement(By.xpath(“input[@type=’text’]))).
build().perform();
driver.quit();
}
}
10. How do u get the attribute of the web element?
The getAttribute() method is used to get attribute of the web element.
Refer below code for get attribute of the web element,
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import java.util.concurrent.TimeUnit;
public class GetSrcAttribute{
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver","C:\\Users\\Credo\\Desktop\\Javaselenium\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
String u = " https://www.credosystemz.com/about/about_careers.htm"driver.get(u);
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
// identify element
WebElement t=driver.findElement(By.xpath("//img[@class='tp-logo']"));
// get src attribute with getAttribute()
System.out.println("Src attribute is : " + t.getAttribute("src"));
driver.close();
}
}
Free PDF : Get our updated Selenium Course Content pdf
11. What is interface?
In general, interface is a completely "abstract class" that is used to group related methods with empty bodies.
Within the Java programming language, an interface (in the glossary) is a type, just as a class is a type. Like a class, an interface defines methods. Unlike a class, an interface never implements methods; instead, classes that implement the interface implement the methods defined by the interface. A class can implement multiple interfaces.
12. What framework used in the project?
Top 3 Selenium framework are:- Data Driven framework
- Keyword Driven framework
- Hybrid framework
13. In day 1 we have only two record in the excel nd tested those data, in day2 the record has increase to 10, How you program write for the dydnamic changes?
14. Write a program to compare 2days and need to print which date is greater need to print the date.kindly provide the steps?
import java.util.Date;
import java.text.SimpleDateFormat;
import java.text.ParseException;
public class CompareDatesExample1
{
public static void main(String[] args) throws ParseException
{
//object of SimpleDateFormat class
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
//dates to be compare
Date date1 = sdf.parse("2020-07-20");
Date date2 = sdf.parse("2020-06-18");
//prints dates
System.out.println("Date 1: " + sdf.format(date1));
System.out.println("Date 2: " + sdf.format(date2));
//comparing dates
if(date1.compareTo(date2) > 0)
{
System.out.println("Date 1 comes after Date 2");
}
else if(date1.compareTo(date2) < 0)
{
System.out.println("Date 1 comes before Date 2");
}
else if(date1.compareTo(date2) == 0)
{
System.out.println("Both dates are equal");
}
}
}
Output:
Date 1: 2020-07-20
Date 2: 2020-06-18
Date 1 comes after Date 2
15. How to count the upper and lower case character of particular string.Need to print the number of upper case and lower case?
public class CountUpperLower {
public static void main(String[] args) {
String str1 = "CredoSystemz";
int upperCase = 0;
int lowerCase = 0;
char[] ch = str1.toCharArray();
for(char chh : ch) {
if(chh >='A' && chh <='Z') {
upperCase++;
} else if (chh >= 'a' && chh <= 'z') {
lowerCase++;
} else {
continue;
}
}
System.out.println("Count of Uppercase letter/s is/are " + upperCase + " and of Lowercase letter/s is/are " + lowerCase);
}
}
Output:
Count of Uppercase letter/s is/are 2 and of Lowercase letter/s is/are 10
16. How do you upload a file?
For Upload a file:
package newproject;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
public class PG9 {
public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver","C:\\geckodriver.exe");
String baseUrl = "http://demo.guru99.com/test/upload/";
WebDriver driver = new FirefoxDriver();
driver.get(baseUrl);
WebElement uploadElement = driver.findElement(By.id("uploadfile_0"));
// enter the file path onto the file-selection input field
uploadElement.sendKeys("C:\\uploadfilename.html");
// check the "Accepting terms and conditions" check box
driver.findElement(By.id("terms")).click();
// click the "UploadFile" button
driver.findElement(By.name("send")).click();
}
17. How do you achieve synchronization in WebDriver?
When two or more components work together, they should work in sync in order to achieve the desired result. If those components are not working in parallel or in sync, you may not get expected result. So, working of those components in sync or in parallel is termed as Synchronization.
In test automation there are usually two components working side by side in parallel, the application being tested and the automation tool
18. What is the use of xpath?
In general, XPath in Selenium is an XML path used for navigation through the HTML structure of the page. Syntax
Xpath=//tagname[@attribute='value'] - For finding any element on a web page using XML path expression.
XPath can be used for both HTML and XML documents to find the location of any element on a webpage using HTML DOM structure.
19. How to perform right click using WebDriver?
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
public class RightClickDemo {
public static void main(String[] args) {
//Note: Following statement is required since Selenium 3.0,
//optional till Selenium 2.0
//Set system properties for geckodriver
System.setProperty("webdriver.gecko.driver", "C:\\Selenium\\credo\\systemz\\geckodriver.exe");
// Create a new instance of the Firefox driver
WebDriver driver = new FirefoxDriver();
// Launch the URL
driver.get("https://demoqa.com/buttons");
System.out.println("demoqa webpage displayed");
//Maximise browser window
driver.manage().window().maximize();
//Instantiate Action Class
Actions actions = new Actions(driver);
//Retrieve WebElement to perform right click
WebElement btnElement = driver.findElement(By.id("rightClickBtn"));
//Right Click the button to display Context Menu
actions.contextClick(btnElement).perform();
System.out.println("Right click Context Menu displayed");
//Following code is to select item from context menu which gets open up on right click, this differs
//depending upon your application specific test case:
//Select and click 'Copy me' i.e. 2nd option in Context menu
WebElement elementOpen = driver.findElement(By.xpath(".//div[@id='rightclickItem']/div[1]"));
elementOpen.click();
// Accept the Alert
driver.switchTo().alert().accept();
System.out.println("Right click Alert Accepted");
// Close the main window
driver.close();
}
}
20. What is the difference between Assert and Verify?
Asserts:
For validate critical functionality we are using Assert .
If the feature fails then this makes the execution of further statements irrelevant. Hence, the test method is aborted as soon as failure occurs.
@Test
public void assertionTest(){
//Assertion Passing
Assert.assertTrue(1+2 == 3);
System.out.println("Passing 1");
//Assertion failing
Assert.fail("Failing second assertion");
System.out.println("Failing 2");
}
Verify:
At times, we might require the test method to continue execution even after the failure of the assertion statements. In TestNG, Verify is implemented using SoftAssert class.
if(isElementPresent(By.linkText("login"))){
System.out.println("Login link is present");
} else{
System.out.println("Login link is not present");
}
Book a Free Mock Interviews and Test your Selenium skills with our Experts
TOP MNC's SELENIUM INTERVIEW QUESTIONS & ANSWERS
Here we listed all Selenium Interview Questions and Answers which are asked in Top MNCs. Periodically we update this page with recently asked Questions, please do visit our page often and be updated in Selenium.
Related Blogs
To become a Selenium Certified professional and join in your dream company, Enroll now for our Best Selenium Training. We help you to crack any levels of Selenium Interviews and We offering Selenium Training with Placement Assistance.