Selenium Interview Questions and Answers

Ace your homework & exams now with Quizwiz!

Explain the methods used to handle dynamic web elements using Selenium?

1. absolute path 2. relative pass using contains or starts with test 3. multiple attributes 4. findElements using index

What are the different methods to refresh a web page in WebDriver?

1. driver.navigate().refresh() 2. driver.get(driver.getCurrentUrl()); 3. F5 key on any textbox using sendKeys command 4. passing ASCII value of F5 key using sendKeys command

How to mouse hover over a web element?

Actions action = new Actions(driver); actions.moveToElement(driver.findElement(By.id("id of the searchbox"))).perform();

What do you mean by the assertion in Selenium?

An assertion is a method of testing whether a particular condition is true or false. In Selenium, assertions are used to verify the state of elements on a page or the results of an action. Assertions can be used to check for the presence or absence of an element, the value of an element, or the text of an element. Assertions can also be used to check that an element is visible or hidden.

What are exactly Jenkins and mention the advantages of using it with Selenium?

Automatic triggering of Selenium tests when code changes are committed to the repository. Parallel execution of Selenium tests on multiple machines to reduce the execution time. Integration with other tools such as JIRA, GitHub, and Slack to provide notifications and status updates.

What are the benefits of automation testing?

Automation testing can be a great way to speed up the software testing process. By automating certain tests, you can save time and resources that would otherwise be spent on manual testing. Additionally, automation can help to improve the accuracy of your tests, as well as provide detailed reports that can help you to identify any areas that need further attention. Overall, automation testing can be a valuable tool for any software development team.

What is POM (Page Object Model)?

Every webpage of the application has a corresponding page class that is responsible for locating the web elements and performing actions on them. Page Object Model is a design pattern that helps create object repositories for the web elements. POM improves code reusability and readability. Multiple test cases can be run on the object repository.

List some of the test types that are supported by Selenium. Different types of testing's that we can achieve through Selenium are.

Functional Testing Regression Testing Sanity Testing Smoke Testing Responsive Testing Cross Browser Testing UI testing (black box) Integration Testing

Which browsers/drivers are supported by Selenium Webdriver?

Google Chrome, Mozilla Firefox, Microsoft Edge, Safari, and Opera.

What are the types of waits supported by WebDriver?

Implicit wait - Implicit wait commands Selenium to wait for a certain amount of time before throwing a "No such element" exception. driver.manage().timeouts().implicitlyWait(TimeOut, TimeUnit.SECONDS); Explicit wait - Explicit wait is used to tell the Web Driver to wait for certain conditions before throwing an "ElementNotVisibleException" exception. WebDriverWait wait = new WebDriverWait(WebDriver Reference, TimeOut); Fluent wait - It is used to tell the web driver to wait for a condition, as well as the frequency with which we want to check the condition before throwing an "ElementNotVisibleException" exception. Wait wait = new FluentWait(WebDriver reference).withTimeout(timeout, SECONDS).pollingEvery(timeout, SECONDS).ignoring(Exception.class);

List out some of the automation tools which could be integrated with Selenium to achieve continuous testing.

JUnit TestNG Cucumber Jenkins GitLab CI/CD Travis CI CircleCI

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

LoadRunner JMeter WebLoad Neoload Silk Performer HP Performance Center Gatling Apache

Mention the types of Web locators.

Locator is a command that tells Selenium IDE which GUI elements it needs to operate on. Locators specify the area of action.

Is Selenium WebDriver a library?

No

Can Captcha be automated?

No, Selenium cannot automate Captcha. Well, the whole concept of Captcha is to ensure that bots and automated programs don't access sensitive information - which is why, Selenium cannot automate it.

Name some of the commonly used automation testing tools that are used for functional automation.

QTP, Test Complete, RFT, and Silk Test.

What is Selenese? How is it classified?

Selenese is the set of Selenium commands which are used to test your web application. The tester can test the broken links, the existence of some object on the UI, Ajax functionality, alerts, window, list options, and a lot more using Selenese. Action: Commands which interact directly with the application Accessors: Allow the user to store certain values to a user-defined variable Assertions: Verifies the current state of the application with an expected state

What are the Selenium suite components?

Selenium IDE Selenium IDE is a browser extension used for creating and executing Selenium tests directly within the browser. Selenium WebDriver WebDriver is a programming interface that helps create and run test cases. Selenium Grid The grid was designed to distribute commands to different machines simultaneously. It allows the parallel execution of tests on different browsers and different operating systems.

What is the difference between Selenium 2.0 and Selenium 3.0?

Selenium RC got deprecated since the merge

Mention the advantages of using Selenium as an automation tool.

Selenium is an automation tool and has some unique benefits that give it a competitive edge over others such as open source, multi-language support, platform support, multi-browser support, framework availability and flexibility, reusability, and integrated and parallel test execution.

What is Selenium?

Selenium is an open-source automation testing suite of tools. The tests can be done in any operating system like Mac, Linux and Windows. Selenium can be combined with some tools, such as TESTNG in Selenium and JUNIT, for managing test cases and generating reports.

How do you deal with stale element exceptions in Selenium?

Stale element exceptions occur when the element you are interacting with is no longer attached to the DOM or has been modified. To handle this exception, you can refresh the page or try to locate the element again using a different locator strategy.

How to take screenshots in WebDriver?

TakeScreenshot interface can be used to take screenshots in WebDriver. getScreenshotAs() method can be used to save the screenshot

Mention the types of listeners in TestNG

TestNG supports three types of listeners: Test listeners: It listens to the test execution and allows us to perform actions before or after a test case is executed. Suite listeners: It listens to the suite execution and allows us to perform actions before or after the suite is executed. Method listeners: It listens to the execution of individual test methods and allows us to perform actions before or after a test method is executed.

Mention the types of listeners in TestNG

TestNG supports three types of listeners: Test listeners: It listens to the test execution and allows us to perform actions before or after a test case is executed. Suite listeners: It listens to the suite execution and allows us to perform actions before or after the suite is executed. Method listeners: It listens to the execution of individual test methods and allows us to perform actions before or after a test method is executed.

What is the difference between "type" and "typeAndWait" command?

The "type" command is used to enter text into a field on a web page. The "typeAndWait" command also enters text into a field, but it waits for the page to load before proceeding to the next command. This can be useful if you are unsure whether or not the text you entered will cause the page to refresh. The main difference between the "type" and "typeAndWait" command is that the "type" command does not wait for the page to reload, while the "typeAndWait" command does. If you are unsure whether or not the text you are entering will cause the page to refresh, it is best to use the "typeAndWait" command. This way, you can be sure that the next command will not be executed until the page has finished loading.

What is the difference between "/" and "//" in XPath?

The difference between "/" and "//" in XPath is that "/" is used to select an element based on its absolute location, while "//" is used to select an element based on its relative location.

What is an exception test in Selenium?

The exception test in Selenium is an exception that you expect will be thrown inside a test class. you can use the test annotation and specify the exception in the parameters.

What is the main disadvantage of implicit wait?

The main disadvantage of implicit wait is that it can slow down your tests. This is because, by default, the implicit wait time is set to zero. As such, if an element is not found immediately, your test will keep trying to find it for the duration of the implicit wait time. This can add a significant amount of time to your test suite. Another disadvantage of implicit wait is that it can cause your tests to fail if the element you are waiting for takes longer to appear than the implicit wait time. Finally, implicit wait can make your tests less reliable because they can introduce flakiness.

What are the WebDriver supported Mobile Testing Drivers?

There are four main WebDriver-supported mobile testing drivers: AndroidDriver, IPhoneDriver, RemoteWebDriver, and Selendroid.

What will happen if I execute this command? driver.get

This command will instruct the Selenium WebDriver to open the specified URL in the web browser.

Which of the following is NOT a type of wait mechanism available in Selenium?

Thread.sleep()

How do you handle a frame in WebDriver?

To handle a frame in WebDriver, we use the switchTo() method.

How to login to any site if it is showing an Authentication Pop-Up for Username and Password?

To handle authentication pop-ups, verify its appearance and then handle them using an explicit wait command.

What are the limitations of Selenium testing?

Unavailability of reliable tech support: Since Selenium is an open-source tool, it does not have dedicated tech support to resolve the user queries. Tests web applications only: Selenium needs to be integrated with third-party tools like Appium and TestNG to test desktop and mobile applications. Limited support for image testing. No built-in reporting and test management facility: Selenium has to be integrated with tools like TestNG, or JUnit among others to facilitate test reporting and management. May require the knowledge of programming languages: Selenium WebDriver expects the user to have some basic knowledge about programming.

How to invoke an application in WebDriver?

When using WebDriver, you can launch applications by either calling the "get" method on the driver instance, or by using the "navigate" method. Applications can also be invoked using a third-party tool such as Selenium IDE. However, doing so requires that you have the URL of the application to be launched beforehand. When using the "get" method, you simply need to pass in the URL of the application as a string.

How do you find broken links in Selenium WebDriver?

When we use driver.get() method to navigate to a URL, it will respond with a status of 200-OK. If any other status is obtained, then it is an indication that the link is broken.

How does Selenium handle Windows-based pop-ups?

Windows-based features are not natively supported by Selenium. However, third-party tools like AutoIT, Robot, etc can be integrated with Selenium to handle pop-ups and other Windows-based features. If the Windows-based pop-up is a web element, getWindowHandles() is used to retrieve all window handles, switchTo().window() is used to switch to the pop-up window

Is there a way to type in a textbox without using sendKeys()?

Yes! Text can be entered into a textbox using JavaScriptExecutor

How to upload a file in Selenium WebDriver?

by using sendkeys() or Robot class method. Locate the text box and set the file path using sendkeys() and click on submit button

How to click on a hyperlink in Selenium?

driver.findElement(By.linkText("Today's deals")).click(); By.patialLinkText()

Which of the following is the correct syntax for locating an element using CSS selectors in Selenium?

driver.find_element(By.CSS_SELECTOR, "#element_id")

Which of the following methods is used to maximize the browser window in Selenium?

driver.maximize_window()

How to scroll down a page using JavaScript?

window.scrollBy

What are the testing types supported by Selenium?

Selenium supports Regression testing and Functional testing. Regression testing - It is a full or partial selection of already executed test cases that are re-executed to ensure existing functionalities work fine. The steps involved are - Re-testing: All tests in the existing test suite are executed. It proves to be very expensive and time-consuming. Regression test selection: Tests are classified as feature tests, integration tests, and the end to end tests. In this step, some of the tests are selected. Prioritization of test cases: The selected test cases are prioritized based on business impact and critical functionalities. Functional testing - Functional Testing involves the verification of every function of the application with the required specification. The following are the steps involved: Identify test input Compute test outcome Execute test Compare the test outcome with the actual outcome

What is a pause on an exception in Selenium IDE?

The user can use this feature to handle exceptions by clicking the pause icon on the top right corner of the IDE. When the script finds an exception it pauses at that particular statement and enters a debug mode. The entire test case does not fail and hence the user can rectify the error immediately.

Mention different ways of locating an element in Selenium?

The various ways of locating an element in Selenium are: by ID, by name, by classname, by tagname, by link text, by partial link text, by CSS selector, and by XPath.

How to set browser window size in Selenium?

The window size can be maximized, set or resized driver.manage().window().maximize(); Dimension d = new Dimension(400,600); driver.manage().window().setSize(d); ((JavascriptExecutor)driver).executeScript("window.resizeTo(1024, 768)");

What are the advantages of automation testing?

There are many advantages of automation testing. Perhaps the most obvious is that it can save you a lot of time and effort. Automation testing can help to speed up the process of testing by automating repetitive tasks, such as running the same test cases multiple times or across different browsers. Another big advantage is that automation testing can improve the accuracy of your tests. By automating the process, you can eliminate human error and ensure that your tests are always carried out the same way. This can be particularly important when testing complex applications where there is a greater risk of errors. Finally, automation testing can also help to improve the coverage of your tests. By automating more of the testing process, you can increase the number of test cases that are run and cover a larger range of functionality. This can help to ensure that your software is thoroughly tested and free of bugs.

Is there an HtmlUnitDriver for .NET?

Yes. To use HtmlUnit first use the RemoteWebDriver and pass it in the desired capabilities.

How to retrieve CSS properties of an element?

getCssValue() driver.findElement(By.id("id")).getCssValue("name of css attribute");

How can we move to the nth-child element using XPath?

(//parent-element/*)[n].

What are the different types of annotations which are used in Selenium?

@Test - This annotation is used to mark a method as a test method @BeforeMethod - This annotation is used to execute a method before each test method @AfterMethod - This annotation is used to execute a method after each test method @BeforeClass - This annotation is used to execute a method before the first test method @AfterClass @DataProvider

What is a Selenium Maven project?

A Selenium Maven project is a software project that uses Maven to manage the project's dependencies and build process.

How do you handle alerts in Selenium?

Alerts can be handled using the Alert interface in Selenium. You can switch to the alert using the switchTo().alert() method and perform actions such as accepting or dismissing the alert using the accept() or dismiss() methods.

What is an Object Repository?

An Object Repository is a centralized location where testers can store all the web elements, such as buttons, text boxes, and links

Mention important details of different types of frameworks and also regarding the connection of Selenium with Robot Framework

Different sets of frameworks are available which can be used with Selenium: Data-Driven Framework: It uses external data sources such as CSV or Excel files to drive the test execution. Keyword-Driven Framework: It uses specific keywords to execute test cases. Hybrid Framework: It is a combination of both Data-Driven and Keyword-Driven frameworks. Selenium can be connected with Robot Framework using the Selenium2Library. The Selenium2Library is a Robot Framework test library that allows us to control web browsers using Selenium WebDriver.

Mention important details of different types of frameworks and also regarding the connection of Selenium with Robot Framework

Different sets of frameworks are available which can be used with Selenium: Data-Driven Framework: It uses external data sources such as CSV or Excel files to drive the test execution. Keyword-Driven Framework: It uses specific keywords to execute test cases. Hybrid Framework: It is a combination of both Data-Driven and Keyword-Driven frameworks. Selenium can be connected with Robot Framework using the Selenium2Library. The Selenium2Library is a Robot Framework test library that allows us to control web browsers using Selenium WebDriver.

How to assert the title of a webpage?

Get the title of the webpage and store in a variable String actualTitle = driver.getTitle(); Assert.assertEquals(actualTitle, expectedTitle);

Is it possible to test APIs or web services using Selenium Webdriver?

No. it is designed to test web-based applications.

How to wait until a web page has been loaded completely in Selenium?

One approach is to use the "implicit wait" command in Selenium, which instructs the web driver to wait a certain amount of time before throwing an error if the element is not found or loaded. Another option is to use the "explicit wait" command to wait for a specific element to appear on the page before proceeding with the script.

How can you redirect browsing from a browser through some proxy?

One way is to use a web proxy. Web proxies can be used to access websites that may be blocked by your network administrator. Another way to redirect browsing is to use a Virtual Private Network (VPN). VPNs can be used to encrypt your traffic and route it through a proxy server. Finally, you can use a browser extension to redirect your traffic. Browser extensions are useful if you want to bypass proxy servers that are configured in your network settings.

what is robot framework?

Robot Framework is a generic open-source test automation framework that provides an easy-to-use, keyword-driven approach to automation.

What is the same-origin policy and how is it handled?

Same Origin policy is a feature adopted for security purposes. According to this policy, a web browser allows scripts from one webpage to access the contents of another webpage provided both the pages have the same origin. The origin refers to a combination of the URL scheme, hostname, and port number.

How to select a value from a dropdown in Selenium WebDriver?

Select class in WebDriver is used for selecting and deselecting options in a dropdown. The objects of Select type can be initialized by passing the dropdown webElement as a parameter to its constructor. WebElement testDrop = driver.findElement(By.id("testingDropdown")); Select dropdown = new Select(testDrop); WebDriver offers three ways to select from a dropdown: selectByIndex: Selection based on index starting from 0 dropdown.selectByIndex(5); selectByValue: Selection based on value dropdown.selectByValue("Books"); selectByVisibleText: Selection of option that displays text matching the given argument dropdown.selectByVisibleText("The Alchemist");

What is Selenium WebDriver?

Selenium WebDriver provides a programming interface to interact with web elements, simulate user actions, and perform automated testing of web applications.

What makes Selenium such a widely used testing tool? Give reasons.

Selenium is easy to use since it's essentially developed in JavaScript. Selenium can test web applications against browsers like Firefox, Opera, Chrome, and Safari, to name a few. The test code can be written in various programming languages like Java, Perl, Python, and PHP. Selenium is platform-independent, and can be deployed on different Operating systems like Windows, Linux, and Macintosh. Selenium can be integrated with third-party tools like JUnit and TestNG for test management.

What is test automation or automation testing?

Test automation or automation testing is the process of using specialized software to control the execution of tests and compare the results with expected outcomes. Automation testing can help reduce the time, cost, and effort required to test software applications by automating repetitive tasks and allowing testers to focus on more critical test cases.

What is exactly meant by a WebElement in Selenium, and how is it used?

The WebElement is an interface in Selenium which is used to represent an HTML element on a web page. It provides methods to interact with the web elements, such as clicking, entering text, and getting the value. It is used to identify and manipulate the web elements in the automation testing process.

Explain the difference between assert and verify commands.

The assert command is used to check if the given condition is true or not. If the condition is true, then the execution of the program will continue. If the condition is false, then the execution of the program will stop. The verify command is used to check if the given condition is true or not. If the condition is true, then the execution of the program will continue. If the condition is false, then the execution of the program will not stop, but an error message will be displayed.

Mention details of the basic steps of Selenium testing and also mention which are the widely used commands via a practical application.

The basic steps of Selenium testing are: Launch a web browser Navigate to a web page Locate web elements Perform actions on web elements Verify the results Some widely used Selenium commands are: get() method: to launch the web page findElement() method: to locate the web element click() method: to click on the web element sendKeys() method: to enter text into the web element getText() method: to retrieve the text from the web element

Explain the pause feature in Selenium IDE.

The pause feature in Selenium IDE allows the tester to add a pause between the execution of two commands. It is used to slow down the test execution to allow for better observation of the test execution flow.

How can you redirect browsing from a browser through some proxy?

There are a few ways to redirect browsing from a browser through some proxy. One way is to use a web proxy. Web proxies can be used to access websites that may be blocked by your network administrator. Another way to redirect browsing is to use a Virtual Private Network (VPN). VPNs can be used to encrypt your traffic and route it through a proxy server. Finally, you can use a browser extension to redirect your traffic. Browser extensions are useful if you want to bypass proxy servers that are configured in your network settings.

how to debug in selenium?

Use logging statements strategically in your test code to track the flow of execution and capture important information Inspect Element Explicit Waits Print Statements Try-Catch Blocks

Write a code snippet to launch Internet Explorer browser in WebDriver.

WebDriver driver = new InternetExplorerDriver(); driver.get("http://www.google.com");

How do you perform drag and drop operations in WebDriver?

When using WebDriver, you can perform drag and drop operations using the Actions class. This class has a number of methods that can be used to perform various actions, such as clicking, dragging, and dropping. In order to use the Actions class, you first need to instantiate it with a WebDriver instance: Actions actions = new Actions(driver); Once you have an Actions instance, you can use the dragAndDrop() method to perform a drag and drop operation. This method takes two WebElements as arguments: the element toDrag, and the element toDrop. For example, to drag an element with the id "draggable" and drop it on an element with the id "droppable", you would do the following: WebElement draggable = driver.findElement(By.id("draggable")); WebElement droppable = driver.findElement(By.id("droppable")); actions.dragAndDrop(draggable, droppable).perform(); You can also use the clickAndHold() and release() methods to perform a drag and drop operation. The clickAndHold() method takes a WebElement as an argument and "grabs" it, while the release() method releases the element. For example: actions.clickAndHold(draggable).release(droppable).perform(); You can also chain together multiple Actions methods to create more complex interactions. For example, the following code will first move to the draggable element, then click and hold it, move to the droppable element, and finally release it: actions.moveToElement(draggable).clickAndHold().moveToElement(droppable).release().perform();

Explain XPath Absolute and XPath attributes.

XPath has two main types of expressions: absolute and relative. Absolute expressions always start with a forward slash (/), which indicates the root element of the document. Relative expressions do not start with a forward slash, and are relative to the current context. Attributes are another important part of XPath. Attributes are added to elements and can contain valuable information about that element. In order to access an attribute, you must use the at sign (@) followed by the attribute name.

What do you mean by XPath?

XPath is a language for addressing parts of an XML document. XSLT and other XML-related technologies use it to access data within XML documents. XPath can be used to navigate through elements and attributes in an XML document. XPath is a major element in the XSLT standard and is crucial for processing XML documents.

What is the major difference between driver.close() and driver.quit()?

driver.close() This command closes the browser's current window. If multiple windows are open, the current window of focus will be closed. driver.quit() When quit() is called on the driver instance and closes all the open browser windows.

Mention the types of navigation commands

driver.navigate().to driver.navigate().refresh(); driver.navigate().forward(); driver.navigate().back();

Which of the following methods is used to clear the text in a text field using Selenium?

element.clear()

When do we use findElement() and findElements()?

findElement() is used to access any single element on the web page. It returns the object of the first matching element of the specified locator. findElements() is used to find all the elements in the current web page matching the specified locator value. All the matching elements would be fetched and stored in the list of Web elements.

What is the difference between getwindowhandles() and getwindowhandle()?

getwindowhandle() method returns the unique identifier of the current browser window, while getwindowhandles() method returns a set of unique identifiers of all the browser windows opened by WebDriver.

How can you find if an element is displayed on the screen?

isDisplayed() isSelected() isEnabled()

How can we type text in a textbox using Selenium?

locate the textbox use the sendKeys() method

How do you simulate a browser back button click in Selenium?

navigate().back() method

What does the switchTo() command do?

switchTo() command is used to switch between windows, frames or pop-ups within the application. Get the window handle of the window you wish to switch to String handle= driver.getWindowHandle();

What is the difference between type keys and type commands?

typeTypeKeys() will trigger JavaScript event in most of the cases whereas .type() won't.

How can we launch different browsers in Selenium WebDriver?

we can use the setWebDriver() method to specify the path to the browser's executable file. Alternatively, we can use the addCustomProfilePreference() method to add a custom profile preference for the browser. Finally, we can use the launchBrowser() method to launch the browser.


Related study sets

EMT: Chapter 15 [respiratory emergency]

View Set

Final Exam Mega Guide (all guides mixed)

View Set

En la estación de tren (In the Train Station)

View Set