• Selenium Video Tutorials

110+ Selenium Interview Questions and Answers (2024)



Selenium is an open-source tool for automation testing. It is primarily used for testing web applications and automating browser interactions. Similar to how a human user would interact with a browser, Selenium allows interaction with web pages such as web page navigation, entering text, clicking buttons, and validating the expected outcome by creating scripts. Developers can test web applications across various browsers and platforms using the robust Selenium framework.

Aspirants looking to excel in Selenium can make use of these top 110+ Selenium interview questions and answers. Whether you are a fresher or an experienced professional, you can test your knowledge of Selenium, and your ability to think critically and solve problems with these questions and answers.

Selenium Interview Questions and Answers

Here is the most frequently asked interview questions and answers on selenium –

1. What is Selenium?

Selenium is a free and open source web automation testing tool. It can be used to perform actions like click, type, mouse and keyboard actions etc on the elements on the web page and validate the outcomes generated after performing them.

Selenium supports multiple languages namely Java, C#, Python, JavaScript etc and can be used in various platforms like Windows, Mac, iPhone, etc. It comprises of a group of tools listed below −

2. What are the components of Selenium?

Selenium is a suite of tools consisting of multiple tools, each of them used to perform various items in web based testing. The Selenium components consist of −

  • Selenium Integrated Development (IDE) − This tool is primarily used for web based testing and popular for the record and playback feature.
  • Selenium Remote Control (RC) − This tool is just like a server and is capable of generating scripts in multiple languages. It takes commands from the tests and directs them to the browser in the form of Selenium core JavaScript commands.
  • Selenium Webdriver − This tool can be used to design test scripts in multiple languages by directly interacting with web browsers
  • Selenium Grid − This tool is used for enabling parallel execution of test scripts on multiple devices, browsers, operating systems etc.

3. What are the advantages we get by using Selenium?

The advantages of using Selenium are listed below −

  • It is open source and does not require any licensing costs.
  • It can be used with multiple browsers like Chrome, Firefox, Safari, Edge etc.
  • It is used to perform testing on various platforms and devices namely, Mac, Windows, iPhones, Androids.
  • It can be integrated with other frameworks like TestNG, Junit etc. Also, it can be used with other build tools, for example Maven, Ant.
  • It can be used to perform headless and parallel execution.
  • It undergoes updates on a regular basis and can be configured very easily. Selenium has a big community support which provides assistance if we are facing issues.
  • It can be used with multiple programming languages like the Java, JavaScript, C#, Ruby, Python, Kotlin etc.
  • It follows a user-friendly interface which helps the user to create and maintain test scripts.
  • It is not a single tool but a collection of tools each of which can be used for different testing purposes.

4. What are the disadvantages we get by using Selenium?

The disadvantages of using Selenium are listed below −

  • It only supports testing of only web based applications.
  • It requires technical knowledge and coding skills.
  • It is not recommended for testing scenarios on barcode, QR scan, captcha etc.
  • It has to be integrated with other tools for report generation.
  • It needs some time prior to being used comfortably with newer versions of browsers and platforms.
  • It does not have any default object repository.

5. What is meant by automation testing and what are its advantages?

Automation testing is the process of converting the manual test cases to automation with the help of testing tools. The manual tests which have a large number of repeated and redundant steps are mostly chosen as the right candidates for automation. However, it must be noted that it is impossible to automate 100% of the manual test cases. Also, automation can be adopted only on a stable software.

The advantages of automation testing are listed below −

  • It can be used for verifying both the functional and non-functional requirements of the software.
  • It has a huge return on investment as it saves a lot of time, money, and human effort.
  • Parallel execution can be achieved through automation.
  • It reduces the scope of human error by avoiding manual intervention in executing the test cases.
  • The time saved through automation can be used to manually test very complex scenarios which can not be automated.
  • It lets the testers execute regression and repeated test cases multiple times in a test cycle.
  • It provides faster feedback on how the software is built.

6. Why is Selenium used extensively for automation?

Selenium is used extensively for automation since it is compatible with multiple browsers, platforms and languages. It does not require any licensing cost.

7. What are known as the Selenese Commands?

Selenese are a group of commands which are used to perform web based testing. These commands are widely used in Selenium IDE. Selenese Commands are of three types, namely Actions, Accessors, and Assertions.

8. What are the differences between Selenium 3.x and Selenium 4.x?

The latest version of Selenium is on the version 4.x. The architecture and communication of this version is W3C compliant. The 3.x version of Selenium’s architecture and communication is based on JSON Wire protocol. The Selenium 4.x has additional relative locators like above(), below(), toRightOf(), toLeftOf(), near(), and chaining of relative locators. It also gives access to the ChromeDevTools which are used for debugging, network traffic analysis, and other features that help in automation.

The Selenium 3.x extends the Remote WebDriver while the Selenium 4.x extends the Chrome Driver. Besides, the 3.x version needs triggering of Hub and Node jars to run Selenium Grid tests, which is no longer required in the 4.x version. Selenium 4.x version provides Selenium IDE Plugins for Chrome and Firefox. It also comes with the side runner in the latest version of Selenium.

9. What are the differences between Selenium 2 and Selenium 3?

What are the differences between Selenium 2 and Selenium 3? Answer: Selenium 3.0 is an improved version of Selenium 2.0 and it has come up with bug fixes of Selenium 2.0 version. Selenium 2.0 was the combination of Selenium RC and Selenium Webdriver. However, Selenium RC became obsolete from the Selenium 3.0 version.

Selenium 2.0 did not have much scope for mobile testing however from Selenium 3.0 mobile testing is carried out using Appium and it has more updated and improved APIs than Selenium 2.0. Selenium 2.0 is no longer in use now.

10. Name some of the tools used for automation testing

Some of the tools used for automation testing are listed below −

  • Selenium − It is mainly used for web based automation testing..
  • Cypress − It is mainly used for web based and API automation testing.
  • Playwright − It is mainly used for web based automation testing.
  • Appium − It is mainly used for mobile automation testing.
  • UFT − It is a licensed web automation testing.
  • JMETER − It is mainly used for load testing.

11. What are the various types of locators available in Selenium?

Selenium identifies elements on the web page with the help of its locating strategies. Some of the locators available in Selenium are listed below −

  • Css
  • Xpath
  • Link Text
  • Partial Link Text
  • Id
  • Name
  • Class Name
  • Tagname

From the latest version of Selenium, there are additional locators available called the relative locators which identify elements with respect to the position of another element. Some of Relative Locators in Selenium are listed below −

  • above()
  • below()
  • toRightOf()
  • toLeftOf()
  • near()
  • Chaining of locators

12. What are the different types of testing that can be done using Selenium?

The different types of testing that can be performed with Selenium are listed below −

  • Regression Testing − This type of testing is performed to verify if code changes have not introduced new bugs in the software.
  • Functional Testing − This type of testing is performed to check if the software is working as per the functional requirements and specifications of the software.

13. What is an Xpath?

The xpath is a query language used to detect elements depending on its XML path. It is utilized to traverse web elements and their attributes of an XML document. To get more information on xpath, please visit the below link −

XML is an extensible markup language used to store, manage, and send data. The data is stored in a key-value pair in a similar format as HTML. Xpath are of two types: relative xpath and absolute xpath.

14. What is an absolute and relative xpath?

The absolute xpath is denoted by the double slash or //. It identifies the desired element starting right from the document’s beginning node. But, if there is a change in path to any element(in between from the root to the current node), the existing absolute xpath will stop working to identify that particular element.

Example

Absolute Xpath Used: /html/body/main/div/div//div/ul/li[2]/input

The relative xpath is denoted by the single slash or /. It identifies the desired element starting from anywhere in the DOM.

Example

Relative Xpath Used: //*[@id='gg_bf_1']//parent::ul

15. What are the differences between driver.close() and driver.quit()?

The driver.close() is used to close the browser window which is presently in focus. In case multiple tabs and windows are opened, the driver.close() will not close all of them. It will only close the tab or the window which is currently active. If the instance of the driver is again invoked after driver.close(), an exception will be thrown on invalid session id.

The driver.quit() is used to close all the opened windows and tabs and terminate the driver session. If the instance of the driver is again invoked after driver.quit(), an exception will be thrown on session id as null.

16. How to wait until a page has been completely loaded using Selenium?

We can wait until a page has been completely loaded using Selenium using the below methods −

Using the Implicit Wait − In this approach, on every page load it shall wait until the page is completely loaded.

For Example

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

Using JavaScript Function − In this approach, invoke the JavaScript return document.readyState till complete is returned post the page load.

For Example

if (document.readyState == "complete"){  
   alert("Page is loaded completely"); 
}

17. What do you mean by exception test in Selenium?

An exception test is the one which anticipates an exception that will be received as an output from a test class. It looks for the @Test annotation then the name of the expected exception within the brackets.

For Example

@Test
public void test1(expectedException = NoSuchElementException.class){

   // description of test method

}

The above exception test for elements which can not be identified.

18. Why is Selenium a popular choice for testing web based applications?

Selenium is a popular choice for testing web based applications because it is a relatively easy tool which is implemented using JavaScript. It is compatible with multiple browsers, platforms, and languages. It can be easily integrated with other third party tools like TestNG, Junit, Maven etc.

19. Name the various annotations used along with Selenium

The various annotations which are used along with the Selenium are usually a part of the TestNG test automation framework. Some of annotations used along with the Selenium are listed below −

  • @BeforeSuite
  • @AfterSuite
  • @BeforeClass
  • @AfterClass
  • @BeforeSuite
  • @AfterSuite
  • @BeforeTest
  • @AfterTest

20. What is known as TestNG in Selenium?

TestNG is a unit test automation framework which can be integrated with Selenium. It enables the use of grouping tests, setting priority to them, parallel testing etc.

21. What is the same-origin policy?

The same-origin policy is a security characteristic applied on browsers that does not allow a document or script belonging to one origin to be accessible to a document or script of another origin. It comprises protocol, origin and port.

Thus a web browser enables scripts from a particular web page to approach another web page if both of them are from a similar origin. The same-origin policy protects a web page’s secured data from the malicious attack from another web page from a different origin.

To avoid the same-origin policy, the proxy injection technique is adopted. In this method, the Selenium server conducts as a client configured HTTP proxy and tricks the browser into accepting that the Selenium Core and the application under test belong to the same origin.

22. Why is Selenium chosen before UFT?

Selenium is mostly chosen over UFT because of the reasons listed below −

  • UFT is a licensed tool and it comes with a cost, whereas Selenium is free and open source.
  • UFT is used to test only the windows applications, whereas the Selenium can test on multiple platforms like Windows, Linus, Mac, iPhone, Blueberry etc.
  • UFT is a desktop application while Selenium is a collection of APIs.
  • UFT is only supported with Visual Basic scripting, whereas the Selenium works with multiple programming languages like Java, C#, Python, JavaScript, Ruby, Kotlin etc.
  • If the testing team is looking for a free, open source tool and is well equipped with the programming languages, then Selenium is always the better choice than UFT. However, if the testing team is only aware of VB scripting and requirement is to verify in the Windows platform, then UFT can be chosen.

23. What is POM or Page Object Model and what are its benefits?

POM also known as Page Object Model is a design pattern that can be used to create Selenium test scripts by separating the elements and test case flows into individual class files. The benefits of POM are that by separating the web elements and the test cases, it gives more code readability, reusability, and easy maintenance.

24. What are the different types of waits available in Selenium?

The different types of waits available in Selenium are listed below −

Implicit Wait

It is of default type where the Selenium waits for a specific amount of time prior to throwing an exception.

For Example

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

Explicit Wait

This wait is used to inform the Webdriver to wait for a specific condition for the given amount of time prior to throwing an exception.

For Example

WebDriverWait w = new WebDriverWait(driver, 15);
wt.until(ExpectedConditions.invisibilityOfElementLocated
   (By.xpath("//*[@class='btn']")));

Fluent Wait

This wait is used to inform the Webdriver to wait for a specific condition at a given interval during which the condition is checked for a particular amount of time prior to throwing an exception.

For Example

Wait w = new FluentWait(driver).withTimeout(25, TimeUnit.SECONDS)
   .pollingEvery(15, TimeUnit.SECONDS) 
   .ignoring(ElementNotInteractableException.class);
   
wt.until(ExpectedConditions.titleIs("Online Tutorialspoint"));

25. What are the differences between the findElement() and finElements() methods in Selenium?

The differences between the findElement() and finElements() methods in Selenium are listed below −

  • The findElement() returns a WebElement, whereas the findElements() returns the list of WebElement.
  • In case there is no matching element, the findElement() throws NoSuchElementException while the findElements() returns an array list with size 0.

26. What is Selenium Webdriver?

Selenium Webdriver is a part of the suite of tools within the Selenium available from the Selenium version 2. It can be used to automate tests on web applications using multiple languages, platforms, and browsers.

27. Is Selenium WebDriver a part of the library?

Selenium Webdriver is a free and open source library used to create automation test scripts for web based applications.

28. What are the different types of navigation commands used in Selenium?

The different types of navigation commands used in Selenium are listed below −

driver.navigate().to("url of application") − It will navigate to the application url.

driver.navigate()
   .to("https://www.tutorialspoint.com/selenium/practice/login.php");

driver.get("url of application") − It will launch the browser to open the application URL.

driver.get("https://www.tutorialspoint.com/selenium/practice/login.php");

driver.navigate().back() − It will help to jump to the previous page as per browser history context.

driver.navigate().back();

driver.navigate().forward() − It will help to jump forward to the next page as per browser history context.

driver.navigate().forward();

driver.navigate().refresh() − It will reload a web page.

driver.navigate().refresh();

29. What is a data driven framework?

A Data Driven framework is one in which the test data is separated from the test script. It allows you to execute a test case against multiple data sets. Also, if there are changes that are required to be made in the test case, those can be done without touching the test data.

30. What all programming languages are supported by Selenium?

Selenium can be used with multiple programming languages like Java, C#, Python, JavaScript, Ruby, Kotlin, Perl etc.

31. What are the differences between driver.get() and driver.navigate.to()?

The differences between driver.get() and driver.naviagte.to() are listed below −

  • The driver.get() method launches a URL and waits for the complete page to load, whereas the driver.naviaget.to() method launches a URL without waiting for the complete page to load.
  • The driver.get() method is a part of the WebDriver interface, whereas the driver.naviaget.to() method is a part of the Navigation interface.
  • The driver.get() method does not allow the browser to move forward or backward to the browser history and its refresh, while the driver.naviaget.to() method allows all these.

32. What scenarios cannot be automated by Selenium?

The scenarios which cannot be automated by Selenium are listed below −

  • It cannot automate scenarios consisting of bitmap comparisons.
  • It cannot automate scenarios on captcha.
  • It cannot automate scenarios on bar codes.
  • The performance tests can be automated by Selenium, but it is not the recommended choice to do so.
  • It cannot automate scenarios on video streaming.

33. Name some of the open source frameworks that can be integrated with Selenium

Some of the open source frameworks that can be integrated with Selenium are listed below −

  • TestNG − It is a unit testing framework which can be integrated with Selenium.
  • JUnit − It is a unit testing framework based on Java.

34. What will happen when the driver.get() method is used in Selenium?

The method driver.get() launches the browser, opens the application URL these, and waits for the complete page to load.

Syntax

driver.get("https://www.tutorialspoint.com/selenium/index.htm");

To get more information on the driver.get(), please visit the link Selenium WebDriver Browser Navigation

35. What is an alternate method to driver.get() method to open an application URL?

The alternate method to driver.get() method to open an application URL is the driver.naviaget.to() method. It launches a URL without waiting for the complete page to load.

Syntax

driver.navigate()
   .to("https://www.tutorialspoint.com/selenium/index.htm");

36. What is a keyword driven framework?

A keyword driven framework is the one in which the implementation logic and the code are hidden. It is a kind of extension to the data driven framework. A set of keywords in a specific sequence are placed to create the test cases in a Keyword Driven Framework.

37. How to upload a file using Selenium?

We can upload files using Selenium. In case the file is in the same machine or placed in a mapped drive, we would need to pass the location of the file to the sendKeys() method.

Syntax

WebDriver driver = new ChromeDriver();

// identify element 
WebElement m = driver.findElement(By.xpath("value of xpath locator"));

// obtain file path to be uploaded
File file = new File("./Pictures.png");
System.out.println("File path to be uploaded: " + file.getAbsolutePath());

// uploading file with path 
m.sendKeys(file.getAbsolutePath());

38. What are the differences between the getWindowHandle() method and the getWindowHandles() method?

The differences between getWindowHandle() method and getWindowHandles() method are listed below −

  • The getWindowHandles() method returns all the handle ids of the windows and tabs currently opened, whereas the getWindowHandle() method returns the handle id of the window or tab which is in focus.
  • The getWindowHandles() method returns all the handle ids of the windows and tabs currently opened using the Collection Set, while the getWindowHandle() method returns the handle id of the Window or Tab which is in focus as a String.

39. What does WebDriver driver = new FireFoxDriver() mean?

In the code statement, WebDriver driver = new FireFoxDriver(), the WebDriver is an interface and the FirefoxDriver is a class. Here, we have created an object of FireFoxDriver class with the help of the new keyword in Java. Then that object is assigned to the reference variable - driver of the WebDriver Interface.

This statement is mostly used in place of FireFoxDriver driver = new FireFoxDriver(), since in automation frameworks, we give the provision to execute tests in multiple browsers. To implement this feature, only the browser name is passed to a reusable method and that reusable method shall create the object of the correct class and finally assign it to the WebDriver interface.

The same can also be done with the statement FireFoxDriver driver = new FireFoxDriver(), however to optimize the code we mostly use WebDriver driver = new FireFoxDriver(). Also, this statement will only have the option to use, and invoke methods of the FireFoxDriver which is applicable for Firefox browser.

We cannot create objects of a specific driver, say FirefoxDriver and assign it to another browser driver, say ChromeDriver. So the statement ChromeDriver driver = new FireFoxDriver() is wrong. But we can assign the objects of FirefoxDriver, ChromeDriver, etc to the WebDriver interface. The statement WebDriver driver = new WebDriver() is not used as WebDriver is an interface and we cannot create objects of an interface.

40. Which is the WebDriver’s super interface?

As per the hierarchy of the classes and interfaces, the SearchContext is the WebDriver’s super interface. The hierarchy of the classes and interfaces in Selenium is described in the below diagram −

WebDriver’s Super Interface

41. How to enter text in a text box in Selenium?

We can enter text in a text box in Selenium with the help of the approaches listed below −

Using sendKeys() Method

Webdriver driver = new ChromeDriver();
driver.findElement(By.id("value of id")).sendKeys("value to be entered"); 

Using the JavaScript Executor

Webdriver driver = new ChromeDriver();
WebElement elm = driver.findElement(By.id("value of id"));
JavascriptExecutor j = (JavascriptExecutor) driver;
j.executeScript("arguments[0].setAttribute('value', 'Selenium')", elm);

Using Actions

Webdriver driver = new ChromeDriver();
Actions a = new Actions(driver);
a.sendKeys(e, "value entered").perform();

42. Can we test APIs and webservices using the Selenium?

Selenium is mainly used for testing the web applications and not used for API Testing. Only the Selenium library is not capable of supporting the API or webservices testing, additional library, for example Rest Assured is required for this purpose.

43. Do we need to use the Selenium Server to execute Selenium Webdriver scripts?

The Selenium Server is used to execute the Selenium Webdriver scripts to trigger parallel execution among multiple platforms, browsers, and machines with the help of the Selenium Grid. If the tests are to be executed in the remote machine, then the remote server is required to execute the test scripts.

44. What do you mean by WebElement in Selenium?

A WebElement is an interface in Selenium that refers to an element on a web page. This is used to perform actions on those elements on the page.

45. How to move to the nth-child of an element with the help of xpath?

We can move to the nth-child of an element with the help of the xpath by following the approaches listed below −

Using the xpath expression - //parent/childElement[n]

//div/a[5]

The above xpath identifies the fifth anchor child for the parent div.

Using the child axes in xpath expression - //parent/child::tagname[n]

Webdriver driver = new ChromeDriver();
WebElement parnt = driver.findElement(By.xpath("//ul[@name='toc']"));

//identify all children nodes with ./child::* expression in xpath
List<WebElement> c = parnt.findElements(By.xpath("./child::*"));

46. Is there an Object Repository in Selenium?

There is a no default Object Repository available in Selenium. However, all the elements locators can be defined in separate class files, properties files etc for easy maintenance and access from the test case.

47. How to insert breakpoints in Selenium IDE?

We insert breakpoints in Selenium IDE to debug test steps. They can be applied by following the methods listed below −

  • Click on the line numbers in the test to add breakpoints.
  • Disable all the breakpoints by pressing Disable breakpoints. The breakpoints get enabled on pressing the same button again.
  • Right clicking on any step, and press Toggle Breakpoint.

48. How to click on a link in Selenium?

We can click on a link in Selenium with the help of the approaches listed below −

Using click() method

Webdriver driver = new ChromeDriver();
driver.findElement(By.linkText("Home")).click(); 

Using the JavaScript Executor

Webdriver driver = new ChromeDriver();
WebElement elm = driver.findElement(By.xpath("//div/ul/li[2]/a"));
JavascriptExecutor j = (JavascriptExecutor) driver;
j.executeScript("arguments[0].click();", elm);

49. How to handle alerts and popups in Selenium?

We can handle Alerts and Popups in Selenium using the Alerts interface. Initially, the driver focus is on the main web page, to access the alerts, we need to shift the driver focus from the main page to them by the switchTo().alert() method.

The methods of the Alert interface are listed below −

  • driver.switchTo().alert().accept() − It accepts an alert and clicks on Ok on an alert.
  • driver.switchTo().alert().dismiss() − It dismisses an alert and clicks on Cancel on an alert.
  • driver.switchTo().alert().getText() − It gets the text on an alert box.
  • driver.switchTo().alert().sendKeys("value") − It enters text appearing on a text field on an alert.

50. What are the differences between assert and verify commands in Selenium IDE?

The assert and verify commands are used to add verification points in the test case. If the condition being checked in an assert command is not satisfied, the execution stops at the point of mismatch. Else the execution is continued. If the condition being checked in a verify command is not satisfied, the execution still continues after the point of mismatch.

51. How to scroll down on a web page in Selenium?

We can scroll down on a web page using Selenium with the help of the JavaScript Executor. To scroll down to a certain height, the scrollBy method is used.

Syntax

JavascriptExecutor j = (JavascriptExecutor) driver;
j.executeScript("window.scrollBy(0,700)", "");

To scroll down to the bottom of the page, again the scrollBy method is used.

Syntax

JavascriptExecutor j = (JavascriptExecutor) driver;
j.executeScript
   ("window.scrollBy(0,document.body.scrollHeight)");

To scroll down to the visibility of an element on the web page.

Syntax

WebElement t = driver.findElement
   (By.xpath("<value of xpath>"));

// scrolling to view of an element
   
JavascriptExecutor j = (JavascriptExecutor) driver;
j.executeScript("arguments[0].scrollIntoView();", t);

52. What is the difference between getText() and getAttribute() methods in Selenium?

The getText() method is used to obtain the element text on a web page. The getAttribute() method is used to get the runtime value of an element in DOM and the value to be obtained is passed as a parameter. Both of them are called the WebElement Commands in Selenium.

Syntax

WebDriver driver = new ChromeDriver();

// Identify the element 
WebElement elm = driver.findElement
   (By.xpath("<value of xpath>"));

// text of the element
String text =  elm.getText());

// Identify another element
WebElement elm1 = driver.findElement
   (By.xpath("<value of id>"));

// enter text in input box
elm1.sendKeys("Selenium Interview");

// Obtain the value entered
String text = elm1.getAttribute("value");

53. How to get a css property of an element?

We can get a css property of an element using the getCSSValue() method. To get the css properties like color or border-color, we need to pass them as the parameters to this method.

Syntax

WebDriver driver = new ChromeDriver();

// Identify the element 
WebElement element = driver.findElement
   (By.xpath("<value of xpath>"));

// Get background color 
String color = element.getCssValue("background-color"));

54. What is the use of @FindBy annotation in Page Factory?

The @FindBy annotation in Page Factory is used to identify, declare and do actions on the web elements using locators like xpath, css, tagname, link text, partial link text, name, class name etc on a web page.

Syntax

FindBy(id = "name") 
WebElement elm;

55. What do you mean by the Hybrid framework?

The hybrid framework is the one which combines the features of both the data driven and keyword driven frameworks. The test scripts built using the Hybrid Framework are more robust, and are found to be more easy to maintain.

56. How to handle frames in Selenium?

We can handle frames in Selenium. Initially, the driver focus is on the main web page, to access the frames, we need to shift the driver focus from the main page to the frames by the switchTo().frame() method.

Some basic overloaded methods on frames are listed below −

switchTo.frame(args) − The frame index number is passed as a parameter. The starting index of the frame is from zero.

driver.switchTo.frame(0), switching to the first frame.

switchTo.frame(args) − The frame id or name is passed as a parameter.

driver.switchTo.frame(“id-value”), switching to the frame 
   having id or name value as id-value.

switchTo.frame(args) − The frame webelement is is passed as a parameter.

driver.switchTo.frame(“id-name”), switching to the frame 
   having webelement value as id-name.

driver.switchTo.defaultContent() − To switch driver context from the frame to the main page.

57. How to clear a text from an input box in Selenium?

We can clear a text from an Input Box in Selenium using the clear() method. At first the text is entered in an input box using the sendKeys() and then cleared by taking help of the clear() method.

58. How to get the value of an element attribute in Selenium?

We can get the value of an element attribute in Selenium by using the getAttribute() method. For example, we can obtain the value entered in a text box using the getAttribute() method and then pass value as a parameter to that method.

Syntax

// Identify element
WebElement textBox = driver.findElement
   (By.className("<value of class name>"));

// Enter text in text box
textBox.sendKeys("Interview Questions");

// Obtain the value entered
String text1 = textBox.getAttribute("value");

59. How to submit a form in Selenium?

We can submit a form using Selenium. The form elements have the tagname as form and the value of its type attribute is equal to submit. To submit a form we can take up the approaches listed below −

Using the submit() method

WebDriver driver = new ChromeDriver();

// Identify element within form
WebElement inputBox = driver.findElement
   (By.xpath("<value of xpath>"));
inputBox.sendKeys("Name");

// Submitting form with submit()
WebElement button = driver.findElement
   (By.xpath("<value of xpath>"));
button.submit();

Using the click() method

WebDriver driver = new ChromeDriver();

// Identify element within form
WebElement inputBox = driver.findElement
   (By.xpath("<value of xpath>"));
inputBox.sendKeys("Name");

// Submitting form with click()
WebElement button = driver.findElement
   (By.xpath("<value of xpath>"));
button.click();

60. What is the architecture of Selenium Webdriver?

The architecture of the Selenium Webdriver in its latest version of 4.x is completely on W3C WebDriver protocol. Earlier the HTTP requests and response from the client to the server was carried out by JSON Wire Protocol. However, from the version 4.x, the communication of the Selenium client library to the browser drivers is done via the W3C WebDriver protocol.

The web browsers and their drivers were already W3C compliant, so the Selenium Webdriver adopted the same protocol so that a standard and common protocol is followed in the entire architecture. It also brings stability to the tests and common code can be used for multiple browsers. Besides the Actions API used in Selenium now provides additional features like two key press, zoom in/out etc.

61. Name some of the exceptions faced in Selenium Webdriver

While working with Selenium we face numerous exceptions. An exception occurs when an element is not found or if there is a mismatch between the expected and actual outcome, or for any other reasons. The code generates an exception to end the test in a logical way.

62. Name some of the commonly used automation testing tools used for non-functional testing

The commonly used automation testing tools used for non-functional testing are listed below −

  • LoadRunner
  • JMeter
  • Silk Performer
  • Gatling
  • Apache
  • Neoload

63. What is the difference between / and // in xpath locator?

The single slash or / refers to the absolute xpath and the double slash or // refers to the relative xpath. The absolute path starts from the root node to locate an element while the relative path starts from anywhere in the DOM to identify an element.

Example

Absolute Xpath Used: /html/body/main/div/div/ul/li[3]/a
Relative Xpath Used: //ul[@id='bn_jn_w']//child::li[3]/a

64. Name the various types of Webdriver API used in Selenium

The various types of Webdriver API used in Selenium are listed below −

  • ChromeDriver
  • FirefoxDriver
  • InternetExplorerDriver
  • HTMLUnitDriver
  • SafariDriver
  • iPhoneDriver
  • RemoteWebDriver
  • AndroidDriver
  • iPhoneSimulatorDriver
  • EventFiringWebDriver

65. How to handle the synchronization problems in Selenium?

We can handle different synchronization problems in Selenium by applying the implicit, explicit, and fluent waits on the tests. These are waits incorporated in the tests so that the Selenium tools and its interaction with the web elements happen in parallel and there is no delay between the two entities.

66. Write the code to launch an application in the Chrome browser.

The code to launch an application in the Chrome browser is given below −

Code Implementation

package org.example;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import java.util.concurrent.TimeUnit;

public class LaunchChromeBrowser {
   public static void main(String[] args) throws InterruptedException {

      // Initiate the Webdriver
      WebDriver driver = new ChromeDriver();

      // adding implicit wait of 15 secs
      driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);

      // Opening the webpage 
      driver.get("https://www.tutorialspoint.com/selenium/practice/radio-button.php");

      System.out.println("Get the page URL: " + driver.getTitle());

      // Closing browser
      driver.quit();
   }
}

67. Write the code to launch an application in the Firefox browser

The code to launch an application in the Firefox browser is given below −

Code Implementation

package org.example;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import java.util.concurrent.TimeUnit;

public class LaunchFirefoxBrowser {
   public static void main(String[] args) throws InterruptedException {

      // Initiate the Webdriver
      WebDriver driver = new FirefoxDriver();

      // adding implicit wait of 15 secs
      driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);

      // Opening the webpage 
      driver.get("https://www.tutorialspoint.com/selenium/practice/radio-button.php");

      System.out.println("Get the page URL: " + driver.getTitle());

      // Closing browser
      driver.close();
   }
}

68. How to get the text of an element in Selenium?

We can get the text of an element in Selenium by using the getText() method.

Syntax

// Identify element
WebElement textBox = driver.findElement
   (By.className("<value of class name>"));

// Obtain the text 
String text1 = textBox.getText();

69. Can we test the mobile applications using Selenium Webdriver?

No we cannot test the mobile applications using the Selenium Webdriver. We test them normally using the Appium which is built on the top of Selenium.

70. How to perform the drag and drop operations in Selenium?

We can perform the drag and drop operations in Selenium with the help of the methods - dragAndDrop() and dragAndDropBy() of the Actions class. The dragAndDrop method has two parameters - source and destination locators. The dragAndDropBy method has three parameters - source locator, x offset value in horizontal direction, and y offset value in vertical direction.

71. How to handle cookies in Selenium?

We can handle cookies in Selenium. We can get, add, and delete cookies. The basic methods on cookies are listed below −

  • addCookie() − It adds a cookie to the current session.
  • getCookieNamed() − It gets a cookie with a specific name among all the created cookies.
  • getCookies() − It gets all the cookies for the current session.
  • deleteCookieNamed() − It deletes a cookie with a particular name, passed as a parameter.
  • deleteCookie() − It deletes a cookie with the cookie object, passed as a parameter.
  • deleteAllCookies() − It deletes all cookies from the current browser session.

72. How to handle multiple windows in Selenium?

We can handle multiple windows in Selenium. Initially, the driver focus is on the main window, to access the other window, we need to shift the driver focus from the main window to the other by using the switchTo().window("child window handle id") method.

The methods to interact with windows are listed below −

  • getWindowHandles() it returns the handle ids of all the windows currently opened using the Collection Set.
  • The getWindowHandle() method returns the handle id of the window which is in focus as a String.

73. How to enter text in a text box without using the sendKeys() method in Selenium?

We can enter text in a text box without using the sendKeys() method. This can also be done with the JavaScript Executor.

Syntax

Webdriver driver = new ChromeDriver();
WebElement element = driver.findElement(By.name("value of name"));
JavascriptExecutor j = (JavascriptExecutor) driver;
j.executeScript("arguments[0].setAttribute('value', 'Interview')", element);

74. How to perform mouse hover actions in Selenium?

We can perform mouse hover actions in Selenium with the help of the moveToElement() method of the Actions Class.

Syntax

WebDriver driver = new ChromeDriver();

// identify element 
WebElement m1 = driver.findElement
   (By.xpath("//div/div[3]/nav/div/a"));
Actions actions = new Actions(driver);
   actions.moveToElement(m1).click().build().perform();

75. What is Page Factory?

The Page Factory is a class which assists in implementing the Page Object Model. It is an extension of the Page Object Model and is available from the WebDriver class.

76. How to select an option in the dropdown in Selenium?

We can select an option in the dropdown using the methods of the Select class. The dropdowns in a web page are represented by select tagname and its options are represented by the options tagname. There are multiple Select class methods in Selenium Webdriver. They are listed below −

getOptions() − It returns the list of all the options.

WebDriver driver = new ChromeDriver();
WebElement elm = driver.findElement(By.id("value of id”))

Select sel = new Select(elm);

List<WebElement> elm1 = sel.getOptions();

getFirstSelectedOption() − It returns the selected option in the dropdown.

WebDriver driver = new ChromeDriver();
WebElement elm = driver.findElement(By.id("value of id”))

Select sel = new Select(elm);

options = sel.getFirstSelectedOption();

isMultiple() − Returns a true value if the dropdown allows selection of multiple items.

WebDriver driver = new ChromeDriver();
WebElement elm = driver.findElement(By.id("value of id”))

Select sel = new Select(elm);

boolean result = sel.isMultiple();

selectByIndex() − The index of the option of the dropdown to be selected is passed as a parameter. The index starts from 0.

WebDriver driver = new ChromeDriver();
WebElement elm = driver.findElement(By.id("value of id”))

Select sel = new Select(elm);

sel.selectByIndex(0);

selectByValue() − The value attribute of the option of dropdown to be selected is passed as a parameter.

WebDriver driver = new ChromeDriver();
WebElement elm = driver.findElement(By.id("value of id”))

Select sel = new Select(elm);

sel.selectByValue("option 5");

selectByVisibleText() − The visible text of the option of the dropdown to be selected is passed as a parameter.

WebDriver driver = new ChromeDriver();
WebElement elm = driver.findElement(By.id("value of id”))

Select sel = new Select(elm);

sel.selectByVisibleText("Interview");

deselectByVisibleText() − The visible text of the option of the dropdown to be deselected is passed as a parameter.

WebDriver driver = new ChromeDriver();
WebElement elm = driver.findElement(By.id("value of id”))

Select sel = new Select(elm);

sel.deselectByVisibleText("Interview");

deselectByValue() − The value attribute of the option of the dropdown to be deselected is passed as a parameter.

WebDriver driver = new ChromeDriver();
WebElement elm = driver.findElement(By.id("value of id”))

Select sel = new Select(elm);

sel.deselectByValue("option 5");

deselectByIndex() − The index of the option of the dropdown to be deselected is passed as a parameter.

WebDriver driver = new ChromeDriver();
WebElement elm = driver.findElement(By.id("value of id”))

Select sel = new Select(elm);

sel.deselectByIndex(0);

deselectAll() − unselects all selected options.

WebDriver driver = new ChromeDriver();
WebElement elm = driver.findElement(By.id("value of id”))

Select sel = new Select(elm);

sel.deselectAll();

getAllSelectedOptions() − returns all the selected options.

77. How to work with hidden elements in Selenium?

We can work with hidden elements in Selenium with the help of the JavaScript Executor

Syntax

WebDriver driver = new ChromeDriver();

   // Javascript executor class 
   JavascriptExecutor j = (JavascriptExecutor) driver;

   // identify hidden element and set value
   j.executeScript
      ("document.getElementById('hidden-field').value='Interview';");
   String st = (String) j.executeScript("return
   document.getElementById('hidden-field').value");

78. What happens when you use both Thread.sleep() and Webdriver waits in Selenium?

The Thread.sleep() stops the test execution for a specific amount of time and the Webdriver waits also to hold the execution for a specific amount of time till a condition is met. If we are using both the waits, it will increase the overall execution time.

79. What happens when you use both implicit and explicit waits in Selenium?

It is not recommended to add both the implicit and explicit waits in the same Selenium tests. While adding both of them in one driver session, it results in uncertain wait time, for example having a combination of explicit wait of 15 seconds and implicit wait of 10 seconds can bring a timeout error after 20 seconds.

An implicit wait is used only once in a test script and is applicable to every test step. However, an explicit wait is used to wait for a particular condition. When both the waits are being applied together, the explicit wait overwrites the implicit wait.

80. What is StaleElementReferenceException and avoid to resolve it?

A StaleElementReferenceException is thrown in a scenario where the Selenium Webdriver tries to search a previously available web element which has currently become unavailable or deleted from DOM. This can happen due to a page refresh, or element or its parent has been removed or deleted. Thus this exception is thrown when the Webdriver fails to interact with that element.

A StaleElementReferenceException can be avoided by the measures listed below −

  • Refresh the page again
  • Wait for that element
  • Make an attempt to access the same element again

81. How Selenium is used to launch the different browsers?

Selenium is used to launch different browsers like Chrome, Firefox, Edge, Safari etc.

Syntax

// For Chrome
WebDriver driver = new ChromeDriver();

// For Firefox
WebDriver driver = new FirefoxDriver();

// For Edge
WebDriver driver = new EdgeDriver();

// For Safari
WebDriver driver = new SafariDriver();

82. What is an Actions class in Selenium?

The Actions class in Selenium is used to carry out keyboards and mouse operations. These include carrying out double click, right click, click, pressing keys, drag and drag actions etc. The Actions class comprises the advanced user interaction APIs.

83. What are the areas where Selenium can contribute more for testing?

The areas where Selenium can contribute more for testing are listed below −

  • Mobile Testing
  • Performance Testing
  • API Testing
  • Default generation of reports
  • Visual Testing
  • Cross Browser Testing

84. What is a testng.xml file?

The testng.xml file is a part of the TestNG unit testing framework. It is used as a configuration file to run the TestNG tests. The tests can be grouped, included or excluded, executed in parallel etc with the help of the testng.xml file.

85. What are assertions in Selenium?

The assertions are verification points added to the test case to verify if the software is working correctly as per the expectations. The assertions are added in the automated test cases to confirm if a test case has passed or failed. The assertion methods are available from the TestNG and the JUnit libraries.

86. How to capture screenshots in Selenium Webdriver?

Selenium Webdriver is used to capture screenshots in the event of failure in a test case. It helps to debug a failed test step. The getScreenShotAs method which is a part of the TakeScreenshot interface is used to capture the screenshots.

Syntax

Webdriver driver = new ChromeDriver();
WebElement l = driver.findElement(By.id("id")); 
l.click();

// take screenshot of link and store in a location
File s = l.getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(s, new File("location of screenshot"));

87. How to press the ENTER key within a text box using Selenium?

We can press the ENTER key within a text box using the sendKeys() method along with the Key class. The Keys.ENTER is to be passed as a parameter to the sendKeys() method to perform this action.

Syntax

WebDriver driver = new ChromeDriver();

// Identify element
WebElement m = driver.findElement(By.name("huj"));
m.sendKeys("Interview");

// Type enter with sendKeys()
m.sendKeys(Keys.ENTER);

88. How to refresh a web page in Selenium?

We can refresh a web page in Selenium in different ways listed below −

Using the Refresh Method

driver.get("https://www.tutorialspoint.com/selenium/index.htm");
driver.navigate().refresh();

Using the sendKeys method

driver.get("https://www.tutorialspoint.com/selenium/practice/text-box.php");
WebElement t = driver.findElement(By.id("fullname"));
t.sendKeys(Keys.F5);

Using the get Method

driver.get("https://www.tutorialspoint.com/selenium/practice/text-box.php");
driver.get(driver.getCurrentUrl());

Using the navigate.to() method

driver.get("https://www.tutorialspoint.com/selenium/practice/text-box.php");
driver.navigate().to(driver.getCurrentUrl());

Using the sendKeys method with ASCII

driver.get("https://www.tutorialspoint.com/selenium/practice/text-box.php");
WebElement t = driver.findElement(By.id("fullname"));
t.sendKeys("\uE035");

89. How to assert the title of a page in Selenium?

We can assert the title of a page in Selenium with the help of the TestNG assertions.

Code Implementation

package org.example;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import java.util.concurrent.TimeUnit;
import org.testng.Assert;

public class AssertBrowserTitle {
   public static void main(String[] args) throws InterruptedException {

      // Initiate the Webdriver
      WebDriver driver = new FirefoxDriver();

      // adding implicit wait of 15 secs
      driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);

      // Opening the webpage 
      driver.get("https://www.tutorialspoint.com/selenium/practice/alerts.php");

      System.out.println("Get the page URL: " + driver.getTitle());
	 
      // obtain page title and compare
      String actTitle = driver.getTitle();
      String title = “Selenium Practice - Alerts";

      Assert.assertEquals
      (actualTitle, expectedTitle);

      // Closing browser
      driver.close();
   }
}

90. Should Selenium be used to verify the captcha?

No Selenium should not be used to verify the captcha.

91. What is a Selenium Maven project?

A Selenium Maven project is one which uses Maven as a build tool and for getting the correct dependencies to run the Selenium project. It also aids in creating a correct project structure for the source code, reusable files, test code etc. Thus Maven helps to achieve easier code maintenance, readability and reliability.

92. Why is switchTo() method used in Selenium?

The switchTo() method is used to shift the driver focus from the main page to another window, tab, alert, frame etc.

93. How to set the browser window size in Selenium?

We can set the browser window size in Selenium with the help of the approaches listed below −

Using the Maximize Method

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

Using the setSize Method

Dimension dimension = new Dimension(500, 500);
driver.manage().window().setSize(dimension);

Using the JavaScript Executor Method

((JavascriptExecutor)driver).executeScript("window.resizeTo(500, 400)");

94. List the automation testing tools which can be integrated with Selenium for continuous integration

Some of the automation testing tools which can be integrated with Selenium for continuous integration are listed below −

  • Jenkins
  • CircleCI
  • AWS CodePipeline
  • Azure Devops
  • Bit Bucket

95. What is the disadvantage of implicit wait?

The implicit wait is a global wait applied to every test step in a test case. Its default wait time is zero and it slows down the execution of tests. Also, it can cause false failure if the element is detected after the given time specified in the implicit wait.

96. Write the code to launch an application in the Internet Explorer browser

The code to launch an application in the InternetExplorer browser is given below −

Code Implementation

package org.example;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.ie.InternetExplorerDriver;
import java.util.concurrent.TimeUnit;

public class LaunchIEBrowser {
   public static void main(String[] args) throws InterruptedException {

      // Initiate the Webdriver
      WebDriver driver = new InternetExplorerDriver();

      // adding implicit wait of 15 secs
      driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);

      // Opening the webpage 
      driver.get("https://www.tutorialspoint.com/selenium/practice/modal-dialogs.php");

      System.out.println("Get URL: " + driver.getTitle());

      // Closing browser
      driver.quit();
   }
}

97. How to navigate back to the browser in Selenium?

We can navigate back to the browser in Selenium using the navigate().back() method. It helps the browser to shift back to the browser history.

98. Explain the working of the Selenium Grid

Selenium Grid is used to support parallel execution across multiple browsers, platforms, devices, and machines. It helps to reduce the execution time and allows efficient usage of resources by distributing the execution in multiple machines. It is based on the hub-node architecture.

99. How to identify the dynamic elements in Selenium?

We can identify the dynamic elements in Selenium by following the approaches listed below −

Using Regular Expressions in Locators

WebDriver driver = new ChromeDriver();

// identify element with partial class match with * in css
WebElement element  = 
   driver.findElement(By.cssSelector("input[name*='inputTxt']"));

Using Regular Expressions in xpath Locators

WebDriver driver = new ChromeDriver();

// Identify element with contains in xpath
WebElement element  = 
   = driver.findElement(By.xpath("//input[contains(@name,'inputTxt')]"))

100. How to set priority to test cases in TestNG?

We can set priority to test cases in TestNG by setting priority parameters to the test methods having the @Test annotations. The lower the number set, the higher is its priority. The default priority for every test method is 0.

101. How to read data from an excel?

We can read data from an excel using the third-party library namely, Apache POI. It helps to access individual cells after traversing through the rows and columns within a sheet inside a workbook.

102. How to perform right click in Selenium?

We can perform a right click on an element with the help of the contextClick() method of the Actions class.

WebDriver driver = new ChromeDriver();

// Identify element 
WebElement element = driver.findElement
   (By.xpath("//div/div/a"));
Actions actions = new Actions(driver);
   actions.moveToElement(element ).contextClick().build().perform();

103. Name the different types of frameworks

The different types of frameworks available are listed below −

104. Name different types of listeners in TestNG.

The different types of listeners used in TestNG are listed below −

  • iTestListener
  • IReporter
  • IHookable
  • IExecutionListener
  • IConfugurable
  • IAnnotationTransformer
  • IConfigurationListener
  • IInvokedMethodListener

105. How to handle windows based popup in Selenium?

Selenium is used only for testing web based applications. To handle windows based popups in Selenium, we have to integrate Selenium with AutoIt or Robot class.

106. What is the ExpectedConditions class in Selenium?

The ExpectedConditions class is a utility class in Selenium that gives specific conditions which should be satisfied before moving to the following step. These are used along with the explicit waits and helps to achieve synchronization in tests. The ExpectedConditions class is used along with the WebdriverWait class to wait for a particular time within which the given criteria should be met, after that again the communication begins with the web elements on the page.

Syntax

WebDriverWait wt = new WebDriverWait(driver, 15);
wt.until(ExpectedConditions.invisibilityOfElementLocated
   (By.id("id value")));

107. How to perform the cross browser testing in Selenium?

The Cross Browser Testing is performed using Selenium to verify if a software is compatible with multiple browsers. To do so, the same tests are executed against various browsers to check if there are any issues. In Selenium, the cross browser testing is mostly implemented with the help of the TestNG unit test automation framework.

108. How to test the login functionality of an application using Selenium Webdriver?

We can identify the login functionality of an application using the Selenium Webdriver. First of all, we have to launch the application URL in a browser. Then we have to identify the username, password, and the login button with the help of any of the locators namely, id, class, name, css, xpath etc available in Selenium. Finally we have to input the username and password with the help of the sendKeys() method and click the login button using the click() method.

Code Implementation

package org.example;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.edge.EdgeDriver;
import java.util.concurrent.TimeUnit;

public class Login {
   public static void main(String[] args) throws InterruptedException {

      // Initiate the Webdriver
      WebDriver driver = new EdgeDriver();

      // adding implicit wait of 10 secs
      driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

      // Opening the webpage
      driver.get("https://www.tutorialspoint.com/selenium/practice/login.php");

      // identify element
      WebElement username = driver.findElement(By.id("email"));
      username.sendKeys("Selenium Java");
      WebElement password = driver.findElement(By.id("password"));
      password.sendKeys("Automation");

      // identify element
      WebElement loginBtn = driver.findElement
         (By.id("//*[@id='signInForm']/div[3]/input"));
      loginBtn.click();

      // Closing browser
      driver.quit();
   }
}

109. What is the difference between type and typeAndWait commands in Selenium?

The type command is used to enter keyboard key values in a text box. It also helps to select an option in the combo box. The typeAndWait command is used when we are done with typing and the web page starts loading. It holds back till the page is loaded before moving to the next steps.

110. Describe the usage of Selenium through a test

Before starting of a Selenium test, the below prerequisites should be satisfied −

  • Download and Install Java & Maven
  • Download and Install any IDE, say IntelliJ
  • Add the Selenium Dependencies

Code Implementation

package org.example;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import java.util.concurrent.TimeUnit;

public class FirstTest {
   public static void main(String[] args) throws InterruptedException {

      // Initiate the Webdriver
      WebDriver driver = new ChromeDriver();

      // adding implicit wait of 15 secs
      driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);

      // Opening the webpage
      driver.get("https://www.tutorialspoint.com/selenium/practice/login.php");

      // identify element to enter email address and password
      WebElement email = driver.findElement(By.id("email"));
      email.sendKeys("Interview");
      WebElement p = driver.findElement(By.id("password"));
      p.sendKeys("Automation");

      // identify login element
      WebElement submitBtn = driver.findElement
         (By.id("//*[@id='signInForm']/div[3]/input"));
      submitBtn.click();

      // Closing browser
      driver.close();
   }
}

111. How to implement the Selenium Webdriver Listeners?

The Selenium Webdriver Listeners can be implemented by the approaches listed below −

  • WebDriverEventListener
  • AbstractWebDriverEventListener

112. How to add a recovery scenario in Selenium Webdriver?

We can add a recovery scenario in Selenium Webdriver by incorporating a try-catch block. It is one of the ways to handle exceptions in the code.

Syntax

try {

   // Perform some tasks
} catch(Exception e1) {

   // Code for the catch block
}

113. Is it possible to work with only build() without perform()?

Yes it is possible to work with only build() without perform(). The build() method constructs and returns an object of the Actions class, which is a collection of a series of actions. If the build() method is not used, the actions are done immediately when perform() is called.

Advertisements