Most Important Selenium Interview Questions
Most Important Selenium Interview Questions
Most Important Selenium Interview Questions
Automation testing or Test Automation is a process of automating the manual task to test the
application/system under test.
Selenium is not just a single tool or a utility, rather a package of several testing tools and for the
same reason it is referred to as a Suite. Each of these tools is designed to cater different testing and
test environment requirements.
Q #5) What are the testing types that can be supported by Selenium?
Selenium supports the following types of testing:
1. Functional Testing
2. Regression Testing
FirefoxDriver
InternetExplorerDriver
ChromeDriver
SafariDriver
OperaDriver
AndroidDriver
IPhoneDriver
HtmlUnitDriver
Syntax:
WebElement username = drv.findElement(By.id(“Email”));
// entering username
username.sendKeys(“sth”);
1. isDisplayed()
2. isSelected()
3. isEnabled()
Syntax:
isDisplayed():
boolean buttonPresence = driver.findElement(By.id(“gbqfba”)).isDisplayed();
isSelected():
boolean buttonSelected = driver.findElement(By.id(“gbqfba”)).isDisplayed();
isEnabled():
boolean searchIconEnabled = driver.findElement(By.id(“gbqfb”)).isEnabled();
Syntax:
String Text = driver.findElement(By.id(“Text”)).getText();
Syntax:
selectByValue:
Select selectByValue = newSelect(driver.findElement(By.id(“SelectID_One”)));
selectByValue.selectByValue(“greenvalue”);
selectByVisibleText:
Select selectByVisibleText = new Select (driver.findElement(By.id(“SelectID_Two”)));
selectByVisibleText.selectByVisibleText(“Lime”);
selectByIndex:
Select selectByIndex = newSelect(driver.findElement(By.id(“SelectID_Three”)));
selectByIndex.selectByIndex(2);
The above mentioned link can also be accessed by using the following command.
driver.findElement(By.partialLinkText(“Goo”)).click();
The above command find the element based on the substring of the link provided in the parenthesis
and thus partialLinkText() finds the web element with the specified substring and then clicks on it.
Select iframe by id
driver.switchTo().frame(“ID of the frame“);
Locating iframe using tagName
driver.switchTo().frame(driver.findElements(By.tagName(“iframe”).get(0));
Locating iframe using index
frame(index)
driver.switchTo().frame(0);
frame(Name of Frame)
driver.switchTo().frame(“name of the frame”);
frame(WebElement element)
Select Parent Window
driver.switchTo().defaultContent();
Sample Code
1 // Storing the list
2 List <WebElement> elementList = driver.findElements(By.xpath("//div[@id='example']//ul//li"));
3 // Fetching the size of the list
4 int listSize = elementList.size();
5 for (int i=0; i<listSize; i++)
6 {
7 // Clicking on each service provider link
8 serviceProviderLinks.get(i).click();
9 // Navigating back to the previous page that stores link to service providers
10 driver.navigate().back();
11 }
Thus, In the following scenario, we have used Action Interface to mouse hover on a drop down
which then opens a list of options.
Sample Code:
1 // Instantiating Action Interface
2 Actions actions=new Actions(driver);
3 // howering on the dropdown
4 actions.moveToElement(driver.findElement(By.id("id of the dropdown"))).perform();
5 // Clicking on one of the items in the list options
6 WebElement subLinkOption=driver.findElement(By.id("id of the sub link"));
7 subLinkOption.click();
Syntax:
driver.findElement(By.id(“id“)).getCssValue(“name of css attribute”);
driver.findElement(By.id(“id“)).getCssValue(“font-size”);
Q #37) What is Junit?
Junit is a unit testing framework introduced by Apache. Junit is based on Java.
@Test: Annotation lets the system know that the method annotated as @Test is a test
method. There can be multiple test methods in a single test script.
@Before: Method annotated as @Before lets the system know that this method shall be
executed every time before each of the test method.
@After: Method annotated as @After lets the system know that this method shall be
executed every time after each of the test method.
@BeforeClass: Method annotated as @BeforeClass lets the system know that this method
shall be executed once before any of the test method.
@AfterClass: Method annotated as @AfterClass lets the system know that this method shall
be executed once after any of the test method.
@Ignore: Method annotated as @Ignore lets the system know that this method shall not be
executed.
Vendor As Selenium is a free tool, user Users can easily get the
Support would not get the vendor’s vendor’s support in case of
Quick Test Professional
Feature Selenium
(QTP)
Q #46) What is Object Repository? How can we create Object Repository in Selenium?
Object Repository is a term used to refer to the collection of web elements belonging to Application
Under Test (AUT) along with their locator values. Thus, whenever the element is required within the
script, the locator value can be populated from the Object Repository. Object Repository is used to
store locators in a centralized location instead of hard coding them within the scripts. In Selenium,
objects can be stored in an excel sheet which can be populated inside the script whenever required.