Selenium Interview Questions

Just spend just 10 minutes every day to master the top Selenium interview questions. This ultimate list of Selenium interview questions and answers will help you to answer on the topics like different Locators supported in Selenium, ways to upload a file using AutoIt tool, the difference between driver.findElement() and driver.findElements() commands, Selenese and different types of Selenese, Page Object Model in Selenium, etc. Start preparing these Selenium technical interview questions and answers, which are for freshers as well as for experienced, and this will land you a good job as a Quality Assurance Engineer or Senior Quality Analyst.

  • 4.7 Rating
  • 11 Question(s)
  • 10 Mins of Read
  • 7651 Reader(s)

Advanced

Download and install AutoIt tool

Open SciTE Script editor and add the below mentioned AutoIt script. Save it as ‘UploadFile.au3’ in your system.

Below is the AutoIt Script:

WinWaitActive("File Upload") 
Send("D:\SoftwareTestingMaterial\UploadFile.txt") 
Send("{ENTER}")

Save it as ‘UploadFile.au3’

After the file is saved, we need to convert the ‘UploadFile.au3’ to ‘UploadFile.exe’. (This can be done by Right Click on the file and click on ‘Compile Script’) .

Add the below mentioned Selenium Script and run :

Runtime.getRuntime().exec(“D:\\Automation\\AutoIt\\Uploadfile.exe”);

The main difference between driver.findElement() and driver.findElements() commands is-

findElement() returns a single WebElement (which is found first) based on the locator passed as the parameter. Whereas findElements() returns a list of WebElements satisfying the locator value passed. It returns an empty list if there are no web elements matching the locator strategy.

Syntax of findElement()-

WebElement textbox = driver.findElement(By.id(“textBoxLocator”));

Syntax of findElements()-

List <WebElement> elements = element.findElements(By.id(“value”));

Another difference between the two is- if no element is found then findElement() throws NoSuchElementException whereas findElements() returns a list of 0 elements.

Page Object Model is an Object Repository design Pattern most commonly used in Selenium Test Automation. It is primarily used for enhancing test maintenance and reducing code duplication. Page object model (POM) can be used in any type of framework - modular, data-driven, hybrid framework or keyword driven, etc. A page object is an object-oriented class that serves as an interface to a page of the Application Under Test (AUT). The tests use these methods of page object class whenever they need to interact with the UI of that page. The benefit is that if there is a UI change, there is no need to change the tests only the code within the page object needs to be changed.

Page Factory in Selenium is an extension to Page Object Model and can be used to initialize web elements that are defined in web page classes or Page Objects.

Page Factory will initialize every WebElement variable with a reference to a corresponding element on the actual web page based on configured “locators”. This is done by using the annotation @FindBy. Example

@FindBy(xpath = "(//option[text()='Basic auth'])[2]")
private WebElement typeSctApp;

Desired Capabilities is used to set properties for the WebDriver. It is also used to set the properties of browser such as to set BrowserName, Platform, Version of Browser etc.

Example :

String baseUrl , nodeUrl;

baseUrl = "https:// https://www.seleniumhq.org/ ";

nodeUrl = "http://192.168.10.21:5568/wd/hub";

DesiredCapabilities dcap = DesiredCapabilities.firefox();

dcap.setBrowserName("firefox");

dcap.setPlatform(Platform.WIN10_1);

driver = new RemoteWebDriver(new URL(nodeUrl),dcap);

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

driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

Selenese is the set of selenium commands which are used for running the tests

There are three types of Selenese :

Actions: These are commands used for performing the operations and interactions with the target elements and manipulate the state of the application

Assertions: These commands are used as checkpoints or verification points. It verifies the state of the application conforms to the expected state.

Accessors: These commands examine the state of the application and store the values in a variables

WebDriver is an Interface which is implemented by FirefoxDriver Class.

FirefoxDriver is a class. It implements all the methods of WebDriver interface.

It makes the reference of the interface and makes an object of FirefoxDriver so as to call implemented methods of WebDriver interface.

We declare the left-hand side variable as WebDriver and right-hand side to create an object for a particular type of the browser and assign it.

WebDriver driver = new FirefoxDriver();

Beginner

Selenium can only be used to test/automate web-based applications. It cannot be used to automate desktop applications.

Selenium WebDriver doesn’t have an inbuilt data-driven testing mechanism. This means the user needs to manually connect automated tests to external data sources.

Selenium doesn't support testing on images. It needs to be integrated with Sikuli for image-based testing

There is no native reporting capability. This can be resolved by integrating it with frameworks like TestNG /JUnit

A Windows-based popup cannot be tested using Selenium alone. AutoIT needs to be used to handle the windows based popups.

Selenium is an open source so there is no dedicated support available for it.

Selenium doesn’t have built-in object repository.

Selenium web driver uses below 8 locators to find the elements on the web page:

  • id – used to select the element with a specified @id attribute.
  • name – used to Select the first element with the specified @name attribute.
  • linkText - used to select link /anchor tag element which contains the matching text
  • PartialLinkText – used to select link (anchor tag) element which contains text matching the specified partial link text.
  • tagName – used to locate the element using its HTML Tag
  • className – used to locate the Element using a class Name
  • cssSelector - used to locate the element using CSS selectors
  • xpath – used to locate the element using an XPath expression.

WebDriver is an Interface. We need to create an Object of the required driver class such as FirefoxDriver, ChromeDriver, InternetExplorerDriver etc.

Syntax to launch Firefox Driver: 

WebDriver driver = 
new FirefoxDriver();
Also to use geckodriver with Selenium, upgrade to Selenium 3.x or higher version  and set the property as follows:
System.setProperty("webdriver.gecko.driver", 
"D:\\Selenium Environment\\Drivers\\geckodriver.exe");

Syntax to launch Chrome Driver: 

WebDriver driver = new 
ChromeDriver();

Syntax to launch Internet Explorer Driver: 

WebDriver driver = new 
InternetExplorerDriver();

Syntax to launch Safari Driver: 

WebDriver driver = new 
SafariDriver();

driver.navigate().forward(); – used to navigate to the next web page with reference to the browser’s history

driver.navigate().back(); – used to take back to the previous web page with reference to the browser’s history

driver.navigate().refresh(); – used to to refresh the current web page i.e. reloading all the web elements

driver.navigate().to(“url”); – used to launch a new web browser window and navigate to the specified URL .

Description

Just spend just 10 minutes every day to master the top Selenium interview questions. This ultimate list of Selenium interview questions and answers will help you to answer on the topics like different Locators supported in Selenium, ways to upload a file using AutoIt tool, the difference between driver.findElement() and driver.findElements() commands, Selenese and different types of Selenese, Page Object Model in Selenium, etc. Start preparing these Selenium technical interview questions and answers, which are for freshers as well as for experienced, and this will land you a good job as a Quality Assurance Engineer or Senior Quality Analyst.
Levels