Selenium Interview Questions

Selenium Interview Questions

Below are most frequently asked question in Interview for selenium topic. 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
  • Thread.sleep().
  • 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
driver.findElement(By.id(“uploadfile_0”)).sendKeys(“C:\\Image.JPG”);
By.id= Provide id of the element after clicking on which pop window comes to choose file. SendKeys=Give path of the file in your system. It can be any file image , pdf , doc etc.
5. What are the different element identification techniques used in selenium Webdriver?
Different element identification techniques used in selenium Webdriver are
  1. By ID //driver.findElement(By.id (“id of element”));
  2. By name //driver.findElement(By.name (“name of element”));
  3. By class name //driver.findElement(By.className (“class name of element”));
  4. By tag name //driver.findElement(By.tagName (“htmltagname of element”));
  5. By link text //driver.findElement(By.linkText (“linktext”));
  6. By partial link text //driver.findElement(By.partialLinkText(“linktext”));
  7. By CSS // driver.findElement(By.cssSelector (“css selector”));
  8. 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.
  1. Go to help.
  2. Click on “Install New Software”.
  3. In “Work with” field enter URL http://beust.com/eclipse/
  4. Wait for TestNG plug-in to download from internet.
  5. 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(“xyz@gmail.com”);
8 .What is absolute xpath and relative xpath?
Below are the examples of absolute xpath and relative xpath.
  • Absolute xpath: /html/body/div[5]/div[2]/div/div[2]/div[2]/h2[1]
  • 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.
System.setProperty(“webdriver.chrome.driver”,”C:\\Setup\\chromedriver.exe”);
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 are the different navigate command available in selenium Webdriver?
Different Navigate commands available in Selenium Webdriver are
driver.navigate.to(); //To launch the website.
driver.navigate.forward(); //To navigate forward.
driver.navigate.back(); //To navigate backward.
driver.navigate().refresh(); ////To refresh the current page
12.How to handle newly popped up window and continue test script execution there?
For this we will have to use three functions getWindowHandle(); driver.getWindowHandles(); switchTo().window();
String home= driver.getWindowHandle(); //To store window handle of the current window.
for (String handle : driver.getWindowHandles())
{
driver.switchTo().window(handle); //To switch to new window.
} //After this control will get transferred to new window.
driver.switchTo().window(home);// To navigate back to home window.
13.How will you handle java script Alert come across execution?
We can handle java script pop-ups using “Alert” class. Alert alert = driver.switchTo().alert(); //Creating object of alert class. alert.accept(): //To accept alert. alert.dismiss(); //To cancel alert. alert.sendKeys(); //To enter text into java script pop-up alert.
14.How to sent text into java script Alert box?
We can send text into text field of java script pop-up by using sendkeys() function.
Alert alert = driver.switchTo().alert(); //Creating object of alert class
alert.sendKeys(“Hello”); //To enter text into java script pop-up alert.
15.What is headless execution?
Headless Execution: It means test script will execute without opening the browser, it can be achieved in selenium by using HTMLUnit driver. WebDriver driver = new HtmlUnitDriver(); //all script below this line will get executed.
16.Write a code to give implicit wait for 10 seconds?
Below is the code to give implicit wait for 10 seconds
driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
17 .What is the difference between close() and quit() function in selenium Webdriver?
Below is the difference between close() and quit() functions. driver.close(); // It is used to close the current browser window. driver.quit(); // It is used to close all open browser windows.
18 .What is the difference between findElemets and findElement?
findElement: Returns path of single WebElement. Example: String x=driver.findElement(By.id(“Element ID”)); //Here we are storing path of only single element. findElements: Returns the path of more than one WebElements. Example: List links=driver.findElements(By. tagName(“a”)); //Here we are storing path of all links.
19.What are the different types of waits available in WebDriver?
There are two mainly two types of waits available in selenium Webdriver Implicit wait and Explicit wait
  • Implicit Wait: In implicit WebDriver will wait for certain amount of time before throwing an “No Such Element Exception”.
Example :
driver.manage().timeouts().implicitlyWait(TimeOut, TimeUnit.SECONDS);
  • Explicit Wait: In explicit wait WebDriver will wait for certain Expected Conditions before throwing an “ElementNotVisibleException” exception. When given time limit is pass and expected condition is not met it will throw an error.
Example :
WebDriverWait wait = new WebDriverWait(WebDriverRefrence,TimeOut); //Creating object of WebDriverWait class.
x = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath( “/html/body/div[1] “)));
x.click();
20.What are the limitations of Selenium?
Limitations of selenium are:
  • Selenium only to test web applications.
  • There is no support available for Selenium. We have to use communities portals such as stackoverflow to resolve any issue.
  • Images compare, captcha entering, barcode reading cannot be automated using selenium Webdriver.
  • There is reporting facility but we can do it using TestNG , JUnit or Cucumber.
  • For using selenium Webdriver you should know at least one programming language for example Java,Python, Ruby etc.



Other Posts

JDBC for Selenium

jdbc for selenium, jdbc driver for selenium, jdbc jar for selenium, jdbc api for selenium,...

Selenium grid

Selenium Grid is a server that allows tests to use web browser instances running on...

GIT

Understanding git fetch commandgit fetch origingit fetch command only downloads new data from a remote...

GIT

Get detail about a particular commitTo get the details about particular commit, you can do...

Java Interview Questions

Java Interview Questions Below are most frequently asked question in Interview for Java topic. Now...

Leave a Reply

Your email address will not be published. Required fields are marked *