Top Selenium Interview Question and Answer
Selenium Interview Question Answer |
- ID
- Name
- ClassName
- LinkText
- PartialLinkText
- TagName
- CssSelector
- XPath
- Implicit Wait
- Explicit Wait
- Fluent Wait
- driver.navigate().to(“URL”)
- driver.navigate().back()
- driver.navigate().forward()
- driver.navigate().refresh()
How to Open Chrome Browser in Selenium WebDriver?
package seleniumproject;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class LaunchBroswer {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty(
"webdriver.chrome.driver",
"D:\\chromedriver-win64\\chromedriver-win64\\chromedriver.exe");
// Instantiate a ChromeDriver class.
WebDriver driver = new ChromeDriver();
}
}
package seleniumproject;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class LaunchBroswer {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty(
"webdriver.chrome.driver",
"D:\\chromedriver-win64\\chromedriver-win64\\chromedriver.exe");
// Instantiate a ChromeDriver class.
WebDriver driver = new ChromeDriver();
driver.get("https://www.qaacharya.in/");
}
}
package seleniumproject;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class LaunchBroswer {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty(
"webdriver.chrome.driver",
"D:\\chromedriver-win64\\chromedriver-win64\\chromedriver.exe");
// Instantiate a ChromeDriver class.
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("https://www.qaacharya.in/");
}
}
How to Rerefrsh the browser Page in Selenium using Java?
Refresh() Method in Selenium is used to refresh the webpage in Selenium.
Selenium Code
package seleniumproject;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class LaunchBroswer {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty(
"webdriver.chrome.driver",
"D:\\chromedriver-win64\\chromedriver-win64\\chromedriver.exe");
// Instantiate a ChromeDriver class.
WebDriver driver = new ChromeDriver();
driver.get("https://www.qaacharya.in/");
driver.navigate().refresh();
}
}
package seleniumproject;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class LaunchBroswer {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty(
"webdriver.chrome.driver",
"D:\\chromedriver-win64\\chromedriver-win64\\chromedriver.exe");
// Instantiate a ChromeDriver class.
WebDriver driver = new ChromeDriver();
driver.get("https://www.qaacharya.in/");
driver.navigate().back();
}
}
package seleniumproject;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class LaunchBroswer {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty(
"webdriver.chrome.driver",
"D:\\chromedriver-win64\\chromedriver-win64\\chromedriver.exe");
// Instantiate a ChromeDriver class.
WebDriver driver = new ChromeDriver();
driver.get("https://www.qaacharya.in/");
driver.navigate().forward();
}
}
- Current Browser Window
- All Browse Window
package seleniumproject;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class LaunchBroswer {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty(
"webdriver.chrome.driver",
"D:\\chromedriver-win64\\chromedriver-win64\\chromedriver.exe");
// Instantiate a ChromeDriver class.
WebDriver driver = new ChromeDriver();
driver.get("https://www.qaacharya.in/");
driver.close();
}
}
package seleniumproject;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class LaunchBroswer {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty(
"webdriver.chrome.driver",
"D:\\chromedriver-win64\\chromedriver-win64\\chromedriver.exe");
// Instantiate a ChromeDriver class.
WebDriver driver = new ChromeDriver();
driver.get("https://www.qaacharya.in/");
driver.quit();
}
}
package seleniumproject;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class LaunchBroswer {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty(
"webdriver.chrome.driver",
"D:\\chromedriver-win64\\chromedriver-win64\\chromedriver.exe");
// Instantiate a ChromeDriver class.
WebDriver driver = new ChromeDriver();
driver.get("https://www.facebook.com/");
//To verify that Element is Displayed
Boolean nn =driver.findElement(By.xpath("//input[ @type=\"text\"]")).isDisplayed();
if(nn) {
System.out.println("Yes ! Element is Present");
}
else {
System.out.println("NO ! Element is not Present");
}
}
}
package seleniumproject;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class LaunchBroswer {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty(
"webdriver.chrome.driver",
"D:\\chromedriver-win64\\chromedriver-win64\\chromedriver.exe");
// Instantiate a ChromeDriver class.
WebDriver driver = new ChromeDriver();
driver.get("https://www.facebook.com/");
//To verify that Element is Displayed
WebElement txtbox= driver.findElement(By.xpath("//input[ @type=\"text\"]"));
txtbox.sendKeys("qaacharya.in@gmail.com");
}
}
package seleniumproject;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class LaunchBroswer {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty(
"webdriver.chrome.driver",
"D:\\chromedriver-win64\\chromedriver-win64\\chromedriver.exe");
// Instantiate a ChromeDriver class.
WebDriver driver = new ChromeDriver();
driver.get("https://www.facebook.com/");
//To verify that Element is Displayed
WebElement Wb= driver.findElement(By.xpath("//input[ @type=\"text\"]"));
Wb.sendKeys("sandeep.uvw@gmail.com");
String txt= Wb.getAttribute("value");
System.out.println(txt);
}
}
package seleniumproject;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class LaunchBroswer {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty(
"webdriver.chrome.driver",
"D:\\chromedriver-win64\\chromedriver-win64\\chromedriver.exe");
// Instantiate a ChromeDriver class.
WebDriver driver = new ChromeDriver();
driver.get("https://www.facebook.com/");
//To verify that Element is Displayed
WebElement Wb= driver.findElement(By.xpath("//input[ @type=\"text\"]"));
Wb.sendKeys("sandeep.uvw@gmail.com");
String txt= Wb.getAttribute("value");
System.out.println(txt);
if (txt.contains("sandeep.uvw@gmail.com"))
{
System.out.println("Yes text is entered ");
}
else
{
System.out.println("Text is not entered ");
}
}
}
package seleniumproject;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class LaunchBroswer {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty(
"webdriver.chrome.driver",
"D:\\chromedriver-win64\\chromedriver-win64\\chromedriver.exe");
// Instantiate a ChromeDriver class.
WebDriver driver = new ChromeDriver();
driver.get("https://www.facebook.com/");
//To verify that Element is Displayed
WebElement txtbox= driver.findElement(By.xpath("//input[ @type=\"text\"]"));
txtbox.sendKeys("qaacharya.in@gmail.com");
txtbox.clear();
}
}
package seleniumproject;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class LaunchBroswer {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty(
"webdriver.chrome.driver",
"D:\\chromedriver-win64\\chromedriver-win64\\chromedriver.exe");
// Instantiate a ChromeDriver class.
WebDriver driver = new ChromeDriver();
driver.get("https://www.facebook.com/");
//To verify that Element is Displayed
WebElement Wb= driver.findElement(By.xpath("//input[ @type=\"text\"]"));
String txt= Wb.getAttribute("value");
if(txt.isEmpty())
{
System.out.println(" Yes Text box is blank");
}
else
{
System.out.println("No Text box is not blank");
}
}
}
package seleniumproject;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class LaunchBroswer {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty(
"webdriver.chrome.driver",
"D:\\chromedriver-win64\\chromedriver-win64\\chromedriver.exe");
// Instantiate a ChromeDriver class.
WebDriver driver = new ChromeDriver();
driver.get("https://www.facebook.com/");
//To verify that Element is Displayed
WebElement Wb= driver.findElement(By.xpath("//input[ @type=\"text\"]"));
//To check /verify the placeholder in selenium
String plcaehld=Wb.getAttribute("placeholder");
if(plcaehld.equals("Email address or phone number"))
{
System.out.println("Valid Place holder");
}
else
{
System.out.println("invalid place holder");
}
}
}
package seleniumproject;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class LaunchBroswer {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty(
"webdriver.chrome.driver",
"D:\\chromedriver-win64\\chromedriver-win64\\chromedriver.exe");
// Instantiate a ChromeDriver class.
WebDriver driver = new ChromeDriver();
driver.get("https://www.facebook.com/");
//To verify that Element is Displayed
WebElement Wb= driver.findElement(By.xpath("//input[ @type=\"text\"]"));
//To check /verify the placeholder in selenium
boolean ebabl= Wb.isEnabled();
if(ebabl) {
System.out.println("Yes ! Element is Present");
}
else {
System.out.println("NO ! Element is not Present");
}
}
}
package seleniumproject;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class LaunchBroswer {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty(
"webdriver.chrome.driver",
"D:\\chromedriver-win64\\chromedriver-win64\\chromedriver.exe");
// Instantiate a ChromeDriver class.
WebDriver driver = new ChromeDriver();
driver.get("https://omayo.blogspot.com/");
//To verify that Element is Displayed
WebElement Wb= driver.findElement(By.xpath("//input[@value='blue']"));
Wb.click();
}
}
package seleniumproject;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class LaunchBroswer {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty(
"webdriver.chrome.driver",
"D:\\chromedriver-win64\\chromedriver-win64\\chromedriver.exe");
// Instantiate a ChromeDriver class.
WebDriver driver = new ChromeDriver();
driver.get("https://omayo.blogspot.com/");
//To verify that Element is Displayed
WebElement Wb= driver.findElement(By.xpath("//input[@value='orange']"));
boolean ab=Wb.isSelected();
if(ab)
{System.out.println("Checkbox is Selected by Default ");
}
else {
System.out.println("No: Check box is Selected by Default");
}
}
}
package seleniumproject;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class LaunchBroswer {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty(
"webdriver.chrome.driver",
"D:\\chromedriver-win64\\chromedriver-win64\\chromedriver.exe");
// Instantiate a ChromeDriver class.
WebDriver driver = new ChromeDriver();
driver.get("https://omayo.blogspot.com/");
//To verify that Element is Displayed
WebElement Wb= driver.findElement(By.xpath("//input[@value='blue']"));
boolean ab=Wb.isSelected();
if(ab)
{System.out.println("Checkbox is Selected by Default ");
}
else {
System.out.println("No: Check box is Selected by Default");
Wb.click();
}
}
}
package seleniumproject;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class LaunchBroswer {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty(
"webdriver.chrome.driver",
"D:\\chromedriver-win64\\chromedriver-win64\\chromedriver.exe");
// Instantiate a ChromeDriver class.
WebDriver driver = new ChromeDriver();
driver.get("https://omayo.blogspot.com/");
//To verify that Element is Displayed
WebElement Wb= driver.findElement(By.xpath("//input[@value='male']"));
Wb.click();
System.out.println("Radio button is selected");
}
}
package seleniumproject;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class LaunchBroswer {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty(
"webdriver.chrome.driver",
"D:\\chromedriver-win64\\chromedriver-win64\\chromedriver.exe");
// Instantiate a ChromeDriver class.
WebDriver driver = new ChromeDriver();
driver.get("https://omayo.blogspot.com/");
//To verify that Element is Displayed
WebElement Wb= driver.findElement(By.xpath("//input[@value='male']"));
boolean ckbx=Wb.isSelected();
if(ckbx)
{
System.out.println("Radio Button is selected by default");
}
else
{
System.out.println("Radio Button is not Selected by default");
}
}
}
package seleniumproject;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class LaunchBroswer {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty(
"webdriver.chrome.driver",
"D:\\chromedriver-win64\\chromedriver-win64\\chromedriver.exe");
// Instantiate a ChromeDriver class.
WebDriver driver = new ChromeDriver();
driver.get("https://omayo.blogspot.com/");
//To verify that Element is Displayed
WebElement Wb= driver.findElement(By.xpath("//input[@value='male']"));
boolean ckbx=Wb.isSelected();
if(ckbx)
{
System.out.println("Radio Button is selected by default");
}
else
{
System.out.println("Radio Button is not Selected by default");
Wb.click();
}
}
}
package seleniumproject;import org.openqa.selenium.By;import org.openqa.selenium.WebDriver;import org.openqa.selenium.WebElement;import org.openqa.selenium.chrome.ChromeDriver;import org.openqa.selenium.support.ui.Select;public class LaunchBroswer {public static void main(String[] args) {// TODO Auto-generated method stubSystem.setProperty("webdriver.chrome.driver","D:\\chromedriver-win\\chromedriver.exe");// Instantiate a ChromeDriver class.WebDriver driver = new ChromeDriver();driver.get("https://omayo.blogspot.com/");WebElement dpdwn= driver.findElement(By.xpath("//select[@id='drop1']"));Select ddwn= new Select(dpdwn);boolean vlu=ddwn.isMultiple();if(vlu){System.out.println("Yes ! Dropdown is Multi Select");}else{System.out.println("NO ! Dropdwn is Not Multi Select");}}}
- selectByIndex
- selectByValue
- selectByVisibleText
package seleniumproject;import org.openqa.selenium.By;import org.openqa.selenium.WebDriver;import org.openqa.selenium.WebElement;import org.openqa.selenium.chrome.ChromeDriver;import org.openqa.selenium.support.ui.Select;public class LaunchBroswer {public static void main(String[] args) {// TODO Auto-generated method stubSystem.setProperty("webdriver.chrome.driver","D:\\chromedriver-win\\chromedriver.exe");// Instantiate a ChromeDriver class.WebDriver driver = new ChromeDriver();driver.get("https://omayo.blogspot.com/");WebElement dpdwn= driver.findElement(By.xpath("//select[@id='drop1']"));Select ddwn= new Select(dpdwn);ddwn.selectByValue("def");}}
- What is Selenium (definition)?
- What are the Selenium suite components?
- What are the advantages of using Selenium as an automation tool?
- What is test automation or automation testing?
- What are the advantages of automation testing?
- What is Selenese? How is it classified?
- What are the limitations of Selenium testing?
- What is the difference between Selenium 2.0 and Selenium 3.0?
- What are the testing types supported by Selenium
- What are the different types of annotations which are used in Selenium?
- Explain the difference between single slash and double slash in XPath.
- What is the same-origin policy and how is it handled?
- Mention the types of Web locators.
- What are the types of waits supported by WebDriver?
- Mention the types of navigation commands
- What is the major difference between driver.close() and driver.quit()?
- What makes Selenium such a widely used testing tool? Give reasons.
- Why is it advised to select Selenium as a testing tool for web applications or systems?
- What is an exception test in Selenium?
- How to wait until a web page has been loaded completely in Selenium?
- What is Selenium WebDriver?
- Is Selenium WebDriver a library?
- Which browsers/drivers are supported by Selenium Webdriver?
- Explain Selenium 4 and why it is different from other Selenium versions?
- What will happen if I execute this command? driver.get
- What is an alternative option to driver.get() method to open a URL in Selenium Web Driver?
- Is it possible to test APIs or web services using Selenium Webdriver?
- How can we move to the nth-child element using XPath?
- How can we type text in a textbox using Selenium?
- How to add text in the text box without using sendkeys()?
- How can you click on a hyperlink in Selenium?
- What is assertion in Selenium and what are the types of assertion?
- What is an object repository?
- Selenium Interview Questions For Experienced
- How to type text in an input box using Selenium?
- How to scroll down a page using JavaScript?
- How to assert the title of a webpage?
- How to mouse hover over a web element?
- How to retrieve the CSS properties of an element?
- Can Captcha be automated?
- How does Selenium handle Windows-based pop-ups?
- Why do testers choose Selenium over QTP?
- What are the data-driven framework and keyword-driven framework?
- What is the difference between getwindowhandles() and getwindowhandle()?
- What is a Selenium Maven project?
- What is exactly meant by a WebElement in Selenium, and how is it used?
0 Comments