We Offer 100% Job Guarantee Courses (Any Degree / Diploma Candidates / Year GAP / Non-IT / Any Passed Outs). Placement Records
Hire Talent (HR):+91-9707 240 250

Interview Questions

Selenium Interview Questions and Answers for Freshers

Selenium Interview Questions and Answers for Freshers

Selenium Interview Questions and Answers for Freshers for beginners and experts. List of frequently asked Selenium Interview Questions with answers by Besant Technologies. We hope these Selenium Interview Questions and Answers for Freshers are useful and will help you to get the best job in the networking industry. This Selenium Interview Questions and Answers for Freshers are prepared by Selenium Professionals based on MNC Companies’ expectations. Stay tuned we will update New Selenium Interview questions with Answers Frequently. If you want to learn Practical Selenium Training then please go through this Selenium Training in Chennai and Selenium Training in Bangalore

Best Selenium Interview Questions and Answers for Freshers

Besant Technologies supports the students by providing Selenium Interview Questions and Answers for Freshers for the job placements and job purposes. Selenium is the leading important course in the present situation because more job openings and the high salary pay for this Selenium and more related jobs. We provide the Selenium online training also for all students around the world through the Gangboard medium. These are top Selenium Interview Questions and Answers for Freshers, prepared by our institute experienced trainers.

Selenium Interview Questions and Answers for Freshers for the job placements

Here is the list of most frequently asked Selenium Interview Questions and Answers for Freshers in technical interviews. These questions and answers are suitable for both freshers and experienced professionals at any level. The questions are for intermediate to somewhat advanced Selenium professionals, but even if you are just a beginner or fresher you should be able to understand the answers and explanations here we give.

Q1. What are the different types of driver implementation?

AndroidDriver, AndroidWebDriver, ChromeDriver, EventFiringWebDriver, FirefoxDriver, HtmlUnitDriver, InternetExplorerDriver, IPhoneDriver, IPhoneSimulatorDriver, RemoteWebDriver, SafariDriver, WebDriverBackedSelenium

Q2. Code for Opening Firefox browser?

Webdriver driver=new FireFoxdriver();

Q3. Which repository you have used to store the test scripts?

I have created scripts in excel file and store them in Test cases folder under src .

Q4. How to work with radio button in web driver?

We can select the value from the drop down by using 3 methods.
selectByVisibleText – select by the text displayed in drop down
selectByIndex – select by index of option in drop down
selectByValue – select by value of option in drop down
xyz abc pqr
WebElement e = driver.findElement(By.id(“44”));
Select selectElement=new Select(e);
// both of the below statements will select first option in the weblist
selectElement.selectByVisibleText(“xyz”);
selectElement.selectByValue(“1”);

Q5. How to work with dynamic web table?

You can get the total number of
tags within a
tag by giving the xpath of the
element by using this function –
List ele = driver.findElements(By.xpath(“Xpath of the table”));
Now you can use a for each loop to loop through each of the tags in the above list and then read each value by using getText() method.

Q6. Detail about TestNG

Test Output folder. It is the directory where reports are generated. Every time tests run in a suite, TestNG
creates index.html and other files in the output directory.

Q7. In frame if no frame Id as well as no frame name then which attribute I should consider throughout our script.

You can go like this…..driver.findElements(By.xpath(“//iframe”))…
Then it will return List of frames then switch to each and every frame and search for the locator which you want then break the loop

Q8. What is object repository?

It is collection of object names their properties, attributes and their values .It maye be excel, XML,property file or text file

Q9. TestNG vs. Junit?

Advantages of TestNG over Junit

  • In Junit we have to declare @BeforeClass and @AfterClass which is a constraint where as in TestNG there is no constraint like this.
  • Additional Levels of setUp/tearDown level are available in TestNG like @Before/AfterSuite,@Before/AfterTest and @Before/AfterGroup
  • No Need to extend any class in TestNG.
  • There is no method name constraint in TestNG as in Junit. You can give any name to the test methods in TestNG
  • In TestNG we can tell the test that one method is dependent on another method where as in Junit this is not possible. In Junit each test is independent of another test.
  • Grouping of testcases is available in TestNG where as the same is not available in Junit.
  • Execution can be done based on Groups. For ex. If you have defined many cases and segregated them by defining 2 groups as Sanity and Regression. Then if you only want to execute the “Sanity” cases then just tell TestNG to execute the “Sanity” and TestNG will automatically execute the cases belonging to the “Sanity” group.
    Also using TestNG your selenium test case execution can be done in parallel.
  • For more Details Go to : http://www.mkyong.com/unittest/junit-4-vs-testng-comparison/
Q10. What is the difference between @beforemethod and @beforeclass.

In JUnit4 @Before is used to execute set of preconditions before executing a test.
For example, if there is a need to open some application and create a user before
executing a test, then this annotation can be used for that method. Method that is
marked with @Before will be executed before executing every test in the class.
If a JUnit test case class contains lot of tests which all together need a method
which sets up a precondition and that needs to be executed before executing the
Test Case class then we can utilise “@BeforeClass” annotation.

Q11. What are the different Parameters for @Test annotation?

Parameters are keywords that modify the annotation’s function.
For more details Go to: http://testng.org/doc/documentation-main.html#parameters

Q12. Can we run group of test cases using TestNG?

Test cases in group in Selenium using TestNG will be executed with the below options.
If you want to execute the test cases based on one of the group like regression test or smoke test
@Test(groups = {“regressiontest”, “smoketest”})
For more details please see: http://testng.org/doc/documentation-main.html#test-groups

Q13. Differences between Selenium web driver, IDE and RC?

Refer – http://qtpselenium.com/selenium-tutorial/difference-between-ide-rc-webdriver/

Q14. How to highlight an object like qtp/uft does through selenium and java?

public void highlightElement(WebDriver driver, WebElement element) {

for (int i = 0; i < 2; i++)
{
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript(“arguments[0].setAttribute(‘style’, arguments[1]);”, element, “color: yellow; border: 2px solid yellow;”);
js.executeScript(“arguments[0].setAttribute(‘style’, arguments[1]);”, element, “”);
}}
Call the highlightElement method and pass webdriver and WebElement which you want to highlight as arguments.

Q15. What are the different assertions in SIDE?

Assertions are like Assessors, but they verify that the state of the application conforms to what is expected. Examples include “make sure the page title is X” and “verify that this check box is checked”.
Assertions are like Accessors, but they verify that the state of the application conforms to what is expected. Examples include “make sure the page title is X” and “verify that this checkbox is checked”.
All Selenium Assertions can be used in 3 modes: “assert”, “verify”, and “waitFor”.
For example, you can “assertText”, “verifyText” and “waitForText”. When an “assert” fails, the test is aborted. When a “verify” fails, the test will continue execution, logging the failure. This allows a single “assert” to ensure that the application is on the correct page, followed by a bunch of “verify” assertions to test form field values, labels, etc.
“waitFor” commands wait for some condition to become true (which can be useful for testing Ajax applications). They will succeed immediately if the condition is already true. However, they will fail and halt the test if the condition does not become true within the current timeout setting (see the setTimeout action below).
For more details – http://selenium-tutorial.blogspot.in/2013/03/selenium-webdriver-assertions.html

Q16. How to store a value which is text box using web driver?

driver.findElement(By.id(“your Textbox”)).sendKeys(“your keyword”);

Q17. How to handle alerts and confirmation boxes.

Confirmation boxes and Alerts are handled in same way in selenium.
var alert = driver.switchTo().alert();
alert.dismiss(); //Click Cancel or Close window operation
alert.accept(); //Click OK
Handle Confirmation boxes via JavaScript,
driver.executeScript(“window.confirm = function(message){return true;};”);

Q18. How to mouse hover on an element?

Actions action = new Actions(webdriver);
WebElement we = webdriver.findElement(By.xpath(“html/body/div[13]/ul/li[4]/a”));
action.moveToElement(we).moveToElement(webdriver.findElement(By.xpath(“/expression-here”))).click().build().perform();

Q19. How to switch between the windows?

private void handlingMultipleWindows(String windowTitle) {
Set windows = driver.getWindowHandles();
for (String window : windows) {
driver.switchTo().window(window);
if (driver.getTitle().contains(windowTitle)) { return; } } }

Q20. How to switch between frames?

WebDriver’s driver.switchTo().frame() method takes one of the three possible arguments:
A number.
Select a frame by its (zero-based) index. That is, if a page has three frames, the first frame would be at index “0”, the second at index “1” and the third at index “2”. Once the frame has been selected, all subsequent calls on the WebDriver interface are made to that frame.
A name or ID.
Select a frame by its name or ID. Frames located by matching name attributes are always given precedence over those matched by ID.
A previously found WebElement.
Select a frame using its previously located WebElement. Get the frame by it’s id/name or locate it by driver.findElement() and you’ll be good.

Q21. What is actions class in web driver?

Actions class with web Driver help is Sliding element, Resizing an Element, Drag & Drop,
hovering a mouse, especially in a case when dealing with mouse over menus.
Actions class with web Driver help is Sliding element, Resizing an Element, Drag & Drop
Hovering a mouse, especially in a case when dealing with mouse over menus.
Dragging & Dropping an Element:
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 testDragandDrop {
public static void main(String[] args) throws InterruptedException {
WebDriver driver = new FirefoxDriver();
driver.get(“http://jqueryui.com/resources/demos/droppable/default.html”);
WebElement draggable = driver.findElement(By.xpath(“//*[@id=’draggable’]”));
WebElement droppable = driver.findElement(By.xpath(“//*[@id=’droppable’]”));
Actions action = new Actions(driver);
action.dragAndDrop(draggable, droppable).perform();
}
}
Sliding an Element:
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 testSlider {
/**
* @param args
* @throws InterruptedException
*/
public static void main(String[] args) throws InterruptedException {
WebDriver driver = new FirefoxDriver();
driver.get(“http://jqueryui.com/resources/demos/slider/default.html”);
WebElement slider = driver.findElement(By.xpath(“//*[@id=’slider’]/a”));
Actions action = new Actions(driver);
Thread.sleep(3000);
action.dragAndDropBy(slider, 90, 0).perform();
}
}
Re-sizing an Element:
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 testResizable {
public static void main(String[] args) throws InterruptedException {
WebDriver driver = new FirefoxDriver();
driver.get(“http://jqueryui.com/resources/demos/resizable/default.html”);
WebElement resize = driver.findElement(By.xpath(“//*[@id=’resizable’]/div[3]”));
Actions action = new Actions(driver);
action.dragAndDropBy(resize, 400, 200).perform();
}
}

Q22. Difference between the selenium1.0 and selenium 2.0?

Selenium 1 = Selenium Remote Control.
Selenium 2 = Selenium Web driver, which combines elements of Selenium 1 and Web driver.

Q23. Difference between find element () and findelements ()?

findElement() :
Find the first element within the current page using the given “locating mechanism”.
Returns a single WebElement.
findElements() :
Find all elements within the current page using the given “locating mechanism”.
Returns List of Web Elements.

Q24. How to take the screen shots in seelnium2.0?

public static void captureScreenShot(String filePath) {
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
try {
FileUtils.copyFile(scrFile, new File(filePath));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

Q25. What is the default time for selenium Ide and webdriver?

Default timeout in selenium ide is 30 seconds.
For web driver go to below URL:
WebDriver Wait Commands

Q26. Write down scenarios which we can’t automate?

Barcode Reader, Captcha etc.

Q27. In TestNG I have some test’s Test1-Test2-Test3-Test4-Test5I want to run my execution order is Test5-Test1-Test3-Test2-Test4.How do you set the execution order can you explain for that?

Use priority parameter in @test annotation or TestNG annotations.
public class testngexecution { @Test(priority=2)public void test1(){System.out.print(“Inside Test1”); }@Test(priority=4)public void test2(){System.out.print(“Inside Test2”); }@Test(priority=3)public void test3(){System.out.print(“Inside Test3”); }@Test(priority=5)public void test4(){System.out.print(“Inside Test4”); }@Test(priority=1)public void test5(){System.out.print(“Inside Test5”); }

Q28. Differences between jxl and ApachePOI. jxl does not support XLSX files

jxl exerts less load on memory as compared to ApachePOI
jxl doesn’t support rich text formatting while ApachePOI does.
jxl has not been maintained properly while ApachePOI is more up to date.
Sample code on Apache POI is easily available as compare to jxl.

Q29. How to ZIP files in Selenium with an Example?

// Sample Function to make zip of reports
public static void zip(String filepath){
try
{
File inputFolder=new File(‘Mention file path her”);
File outputFolder=new File(“Reports.zip”);
ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(outputFolder)));
BufferedInputStream in = null;
byte[] data = new byte[1000];
String files[] = inputFolder.list();
for (int j=0; j<files.length; i++)
{
in = new BufferedInputStream(new FileInputStream
(inputFolder.getPath() + “/” + files[j]), 1000);
out.putNextEntry(new ZipEntry(files[j]));
int totalcount;
while((totalcount= in.read(data,0,1000)) != -1)
{
out.write(data, 0, totalcount);
}
out.closeEntry();
}
out.flush();
out.close();
}
catch(Exception e)
{
e.printStackTrace();
return “Fail – ” + e.getMessage();
}
}

Q30. What is default port no?

4444

Q31. If Default port no is busy how to change port no?

We can use any port number which is valid.. First create an object to remote control configuration.
Use ‘setPort’ method and provide valid port number(4545,5555,5655, etc).. There after attach this
remote control configuration object to selenium server..i.e
RemoteControlConfiguration r= new RemoteControlConfiguration();
r.setPort(4567);
SeleniumServer s= new SeleniumServer(r);

Q32. Does Selenium support https protocols?

Yes

Q33. Majorly asked test scenario with framework in Interviews?

Majorly asked are:
Login for Gmail scenario
Goggle search and finding no of results
Downloading a file and save it
Checking mails and deleting them
Do shopping in flipkart.com

Q34. Selenium support mobile applications?

No, it is browser automation tool, it only automates Websites opening in mobile browser, and mobile APPs can’t be automated.

Q35. What is wraps Driver?

For casting selenium instance to selenium2 (webdriver). wraps driver is used.
For more details.
http://selenium-junit4-runner.btmatthews.com/apidocs/com/btmatthews/selenium/junit4/runner/WrappedDriverFactory.html

Q36. Can you explain Junit Annotation?

If there are 1000 test cases. 500 test cases are executed. How will you execute the rest of the test cases by using annotation? The annotations generated with JUnit 4 tests in Selenium are:
@Before public void method() – Will perform the method() before each test. This method can prepare the test
@Test public void method() – Annotation @Test identifies that this method is a test method.environment,e.g. read input data, initialize the class)
@After public void method() – Test method must start with test@Before – this annotation is used for executing a method before

Q37. Difference between assert and verify in selenium web driver.

When an “assert” fails, the test will be aborted. Assert is best used when the check value has to pass for the test to be able to continue to run log in.
Where if a “verify” fails, the test will continue executing and logging the failure. Verify is best used to check non critical things. Like the presence of a headline element.

Q38. “I want to find the location of “”b”” in the below code, how can I find out without using xpath, name,id, csslocator, index. a b c

driver.findElement(By.xpath(“//*[contains(text(),’b’)]”)).click(); or
• //div/button[contains(text(),’b’]

Q39. How to do Applet testing using selenium?

Please see below URLs:
http://docs.codehaus.org/display/FEST/Selenium
https://code.google.com/p/festselenium/

Q40. Name 5 different exceptions you had in selenium web driver and mention what instance you got it and how do you resolve it?

WebDriverException
NoAlertPresentException
NoSuchWindowException
NoSuchElementException
TimeoutException
WebDriverException
WebDriver Exception comes when we try to perform any action on the non-existing
driver.
WebDriver driver = new InternetExplorerDriver();
driver.get(“http://google.com”);
driver.close();
driver.quit();
NoAlertPresentException
When we try to perform an action i.e., either accept() or dismiss() which is not required
at a required place; gives us this exception.
try{
driver.switchTo().alert().accept();
}
catch (NoAlertPresentException E){
E.printStackTrace();
}
NoSuchWindowException
When we try to switch to an window which is not present gives us this exception:
WebDriver driver = new InternetExplorerDriver();
driver.get(“http://google.com”);
driver.switchTo().window(“Yup_Fail”);
driver.close();
In the above snippet, line 3 throws us an exception, as we are trying to switch to an
window that is not present.
Similar to Window exception, Frame exception mainly comes during switching between the frames.
WebDriver driver = new InternetExplorerDriver();
driver.get(“http://google.com”);
driver.switchTo().frame(“F_fail”);
driver.close();
In the above snippet, line 3 throws us an exception, as we are trying to switch to an
frame that is not present.
NoSuchElementException
This exception is thrown when we WebDriver doesn’t find the web-element in the DOM.
WebDriver driver = new InternetExplorerDriver();
driver.get(“http://google.com”);
driver.findElement(By.name(“fake”)).click();
TimeoutException
Thrown when a command does not complete in enough time.
All the above exceptions were handled using try catch exceptions.

Q41. How do you manage the code versions in your project?

Using SVN or other versioning tools

Q42. Latest version of Firefox and selenium in market and the version on which you are testing which you are testing.

FF Latest version till Dec,2013 for windows7,64 bit :26.0.I use FF 25.0.1 (ur ans. may differ)
Selenium web driver latest version till dec,2013- 2.39.0 I use selenium 2.37 see latest at http://www.seleniumhq.org/download/

Q43. How to know all the methods supported in web driver and its syntax.

In Org.openqa.selenium package, web driver interface has all the main methods that can be used in Selenium Web driver
HTTP://docs.seleniumhq.org/docs/03_webdriver.jsp

Q44. How do you create html test report from your test script?

I would see below 3 ways:
Junit: with the help of ANT.
TestNG: using inbuilt default.html to get the HTML report. Also XLST reports from ANT, Selenium, TestNG combination.
Using our own customized reports using XSL jar for converting XML content to HTML.

Q45. List the browsers, OS supported by the Selenium Windows Linux Mac

IE Y NA NA
FF Y Y Y
Safari Y N Y
Opera Y Y Y
Chrome Y Y Y

Q46. Can you explain Selenium Mobile Automation?

Some Good urls’s till the time i write custom document for it.
https://code.google.com/p/selenium/wiki/AndroidDriver
http://manojhans.blogspot.in/2013/08/native-android-apps-automation-with.html

Q47. What mobile devices it may Support?

Selenium Web driver supports all the mobile devices operating on Android, IOS operating Systems
Android – for phones and tablets (devices & emulators)
iOS for phones (devices & emulators) and for tablets (devices & emulators)

Q48. What are the test types supported by Selenium?

Selenium supports UI and functional testing. As well it can support performance testing
for reasonable load using selenium grid.

Q49. In what all case we have to go for “JavaScript executor”.

Consider FB main page after you login. When u scrolls down, the updates get loaded. To
handle this activity, there is no selenium command. So you can go for javascript to set
the scroll down value like driver.executeScript(“window.scrollBy(0,200)”, “”);

For More Selenium Interview Questions -> Refer – Selenium Interview Questions and Answers

Besant Technologies WhatsApp