Selenium Interview Questions
Below Are Most Frequently Asked Selenium Interview Questions. Below Content Is For Interview Preparation You Can Read Below Questions And Answers Before Your Interview To Revised The Concepts You Already Know.
1.How will you clear the contents from input box on Web page using Selenium Webdriver?
We can clear the contents from input box on Web page using Selenium Webdriver using below code.
driver.findElement(By.xpath(“xpath of text field”)).clear();
2 .What are the ways for synchronize between script execution and application?
Below are the different ways in which synchronize between script execution and application are maintained
- Explicit Wait.
- Implicit Wait.
3.What is fluentWait?
A FluentWait instance defines the maximum amount of time to wait for a condition to take place, as well as the frequency with which to check the existence of the object condition. //Waiting 60 seconds for an element to be present on the page, checking for its presence once every 10 seconds.
Wait wait = new FluentWait(driver).withTimeout(60, SECONDS).pollingEvery(10,SECONDS).ignoring(NoSuchElementException .class);
4.How to upload document on a web page using selenium Webdriver?
We can upload any file using below code
5. What are the different element identification techniques used in selenium Webdriver?
Different element identification techniques used in selenium Webdriver are
- By ID //driver.findElement(By.id (“id of element”));
- By name //driver.findElement(By.name (“name of element”));
- By class name //driver.findElement(By.className (“class name of element”));
- By tag name //driver.findElement(By.tagName (“htmltagname of element”));
- By link text //driver.findElement(By.linkText (“linktext”));
- By partial link text //driver.findElement(By.partialLinkText(“linktext”));
- By CSS // driver.findElement(By.cssSelector (“css selector”));
- By Xpath // driver.findElement(By.xpath (“xpath”));
6.How to configure TestNG with selenium?
To configure TestNG we have to add plug-in of TestNG into Eclipse below are the steps to do it.
- Go to help.
- Click on “Install New Software”.
- In “Work with” field enter URL http://beust.com/eclipse/
- Wait for TestNG plug-in to download from internet.
- Click on finish.
7 .Write a code to enter E-mail id into Username field using selenium WebDriver?
Code to enter E-mail id into Username field using selenium WebDriver :
driver.findElement(By.xpath(“xpath of text field”)).sendKeys(“email@example.com”);
8 .What is absolute xpath and relative xpath?
Below are the examples of absolute xpath and relative xpath.
- Absolute xpath: /html/body/div/div/div/div/div/h2
- Relative xpath: //*[@id=”username”]
9.How to set Chrome driver properties and driver path in project?
You can set Chrome driver properties and driver path in project using below code.
10.Write selenium code to click on submit button having id=“Submit”.
set Chrome driver properties and driver path in project.
driver.findElement(By.xpath(“xpath of button”)).click();
11.What is the difference between WebDriver and RemoteWebDriver in Selenium?
- Remote Web Driver requires the selenium-server-standalone to be running (the others do not). This could be running on the same machine or a “remote” one.
- If we want to use the browser on the machine that is running the automation, then we can use everything but RemoteWebDriver.
- The major difference is that RemoteWebDriver sends that request to open and control a web browser to a server, so you normally wouldn’t see the browser open and do it’s thing.
- If we are using Selenium Grid then it is mandatory to use Selenium Webdriver.
12.What are the best practices for maintaining the testing framework using Selenium webdriver using Java?
- Using page object model with PageFactory : In page Object model we create an class of each page of our application. The goal is to encapsulate the functions of each page in a page object, and to use these objects in the test our Test scripts.
- Keeping test scripts separate from Java implementation code : Keep it in a separate directory for clarity. Test scripts should be readable by a product manager or other non-programmer. It’s a good practice to keep test scripts separate and creating packages module wise. If they are getting unmanageable, consider them refactoring.
- Use Maven for managing jar dependencies : Maven is very good build management tool and you can easily manage you dependencies from POM.xml
- Use TestNG instead of Junit : In TestNG you get lots of options such as grouping test cases Assertions , Paraller execution , You can easily execute group of test cases with help of TestNG.xml file.
- Use drivers instantiation such as new FireFoxDriver, new ChromeDriver in Before Annotations: As your script use @BeforeClass or @BeforeTest or any other @Before annotation of create an instance of your browser. To avoid the repetition of this code as it is very basic and needed scipt will be get used everywhere.
- Using Good Reporting tool – You can keep you managers and stack holders happy with beautiful reports such as extent reports like Allure Reports , ReportNG and these will collate your results into something readable and Presentable.
- If possible Use Jenkins : May be you are at early stage of your Automation framework development and environment is not stable yet but whenever possible use Jenkins for scheduling jobs and sending mails in case of build failure.