Beginner level
1 What are the Selenium suite components?
1 What are the Selenium suite components? Selenium suite Selenium IDE It is a Firefox/Chrome plug-in that was developed to speed up the creation of automation scripts. It records the user actions on the web browser and exports them as a reusable script
1 What are the Selenium suite components? Selenium suite Selenium Remote Control (RC) RC is a server that allows users to write application tests in various programming languages. The commands from the test script are accepted by this server and are sent to the browser as Selenium core JavaScript commands. The browser then behaves accordingly
1 What are the Selenium suite components? Selenium suite Selenium WebDriver WebDriver is a programming interface that helps create and run test cases. It makes provision to act on web elements. Unlike RC, WebDriver does not require an additional server and interacts natively with the browser applications
1 What are the Selenium suite components? Selenium suite Selenium Grid Grid was designed to distribute commands to different machines simultaneously. It allows the parallel execution of tests on different browsers and different operating systems. It is exceptionally flexible and is integrated with other suite components for simultaneous execution
2 What are the limitations of Selenium?
2 What are the limitations of Selenium? No reliable tech support
2 What are the limitations of Selenium? No reliable tech support Tests only web applications
2 What are the limitations of Selenium? No reliable tech support Limited support for image testing Tests only web applications
What are the limitations of Selenium? No reliable tech support Limited support for image testing No built in reporting facility 2 Tests only web applications
What are the limitations of Selenium? No reliable tech support Limited support for image testing Tests only web applications No built in reporting facility Limited test management 2
What are the limitations of Selenium? No reliable tech support Limited support for image testing No built in reporting facility Limited test management May require knowledge of programming languages 2 Tests only web applications
3 What are the testing types supported by Selenium?
3 What are the testing types supported by Selenium? Selenium supports Regression testing and Functional testing
3 What are the testing types supported by Selenium? Selenium supports Regression testing and Functional testing Regression testing Re-testing Prioritization of test cases Regression test selection Regression Testing is a full or partial selection of already executed test cases which are re-executed to ensure existing functionalities work fine. Steps involved are…
3 What are the testing types supported by Selenium? Selenium supports Regression testing and Functional testing Regression testing Re-testing Prioritization of test cases Regression test selection Regression Testing is a full or partial selection of already executed test cases which are re-executed to ensure existing functionalities work fine. Steps involved are… • All tests in the existing test suite are executed • Very expensive and time consuming
3 What are the testing types supported by Selenium? Selenium supports Regression testing and Functional testing Regression Testing is a full or partial selection of already executed test cases which are re-executed to ensure existing functionalities work fine Steps involved are… Regression testing Re-testing Prioritization of test cases Regression test selection Tests are classified as • Feature tests • Integration tests • End to End tests Some of these tests are selected
3 What are the testing types supported by Selenium? Selenium supports Regression testing and Functional testing Regression Testing is a full or partial selection of already executed test cases which are re-executed to ensure existing functionalities work fine Steps involved are… Regression testing Re-testing Prioritization of test cases Regression test selection The selected test cases are prioritized based on business impact and critical functionalities
3 What are the testing types supported by Selenium? Selenium supports Regression testing and Functional testing Functional Testing involves the verification of every function of the application with the required specification. Identify test input Compute test outcome Execute test Compare the test outcome with the actual outcome Functional testing
4 What are Selenium 2.0 and Selenium 3.0?
4 Selenium 2.0 is a tool that makes the development of automated tests for web applications easier. It represents the merger of the original Selenium project with the WebDriver project. Selenium RC got deprecated since the merge, however was used for backward compatibility. Selenium 2 Selenium IDE Selenium RC Grid Selenium WebDriver What are Selenium 2.0 and Selenium 3.0?
4 Selenium 2.0 is a tool that makes the development of automated tests for web applications easier. It represents the merger of the original Selenium project with the WebDriver project. Selenium RC got deprecated since the merge, however was used for backward compatibility. Selenium 2 Selenium IDE Selenium RC Grid Selenium WebDriver Selenium 3 Selenium IDE Selenium WebDriver Grid Selenium 3.0 is the extended version of Selenium 2.0. It is inherently backward compatible and does not involve Selenium RC. The new version came along with several bug fixes and increased stability. What are Selenium 2.0 and Selenium 3.0?
5 What is Same Origin policy? How is it handled?
5 What is Same Origin policy? 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
5 What is Same Origin policy? 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 Origin is a combination of URL scheme, hostname and port number. Same Origin policy prevents a malicious script on one page to access sensitive data on another webpage
5 What is Same Origin policy? 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 Consider a JavaScript program used by google.com. This test application can access all Google domain pages like google.com/login, google.com/mail, etc.
5 What is Same Origin policy? 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 However, it cannot access pages from other domains like yahoo.com
5 What is Same Origin policy? How is it handled? Selenium RC was introduced to address this. The server acts as a client configured HTTP proxy and "tricks" the browser into believing that Selenium Core and the web application being tested come from the same origin. RC server 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 Test script
6 What is Selenese? How is it classified?
6 What is Selenese? How is it classified? Selenese is the set of Selenium commands which are used to test your web application. Tester can test the broken links, existence of some object on the UI, Ajax functionality, alerts, window, list options and lot more using Selenese
6 What is Selenese? How is it classified? Selenese is the set of Selenium commands which are used to test your web application. Tester can test the broken links, existence of some object on the UI, Ajax functionality, alerts, window, list options and lot more using Selenese Action Accessors Assertions Commands which interact directly with the application Allow the user to store certain values to a user-defined variable Verifies the current state of the application with an expected state Selenium commands
7 Mention the types of web locators.
7 Mention the types of web locators. Locator is a command that tells Selenium IDE which GUI elements ( say Text Box, Buttons, Check Boxes etc) it needs to operate on. Locators specify the area of action
7 Mention the types of web locators. Locator is a command that tells Selenium IDE which GUI elements ( say Text Box, Buttons, Check Boxes etc) it needs to operate on. Locators specify the area of action Locator by ID: It takes a parameter of String which is a Value of ID attribute and it returns the object to findElement() method. driver.findElement(By.id(“user”)); Locator by link: If your targeted element is link text then you can use by link text element locator to locate that element driver.findElement(By.linkText(“Today’s deals”)).click(); Locator by Partial link: The target link can be located using a portion of text in a link text element. driver.findElement(By.linkText(“Service”)).click(); Locator by Name: The first element with the name attribute value matching the location will be returned driver.findElement(By.name(“books”).click());
7 Mention the types of web locators. Locator is a command that tells Selenium IDE which GUI elements ( say Text Box, Buttons, Check Boxes etc) it needs to operate on. Locators specify the area of action Locator by TagName: Locates all the elements with the matching tag name driver.findElement(By.tagName(“button”).click()); Locator by classname: This finds elements based on the value of the CLASS attribute. If an element has many classes then this will match against each of them. driver.findElement(By.className(“inputtext”)); Locator by XPath: It takes a parameter of String which is a XPATHEXPRESSION and it returns an object to findElement() method driver.findElement(By.xpath(“//span[contains(text(),’an account’)]”)).getText(); Locator by CSS Selector: Locates elements based on the driver’s underlying CSS selector engine. driver.findElement(By.cssSelector(“input#email”)).sendKeys(“myemail@email.com”);
8 What are the types of waits supported by WebDriver?
8 What are the types of waits supported by WebDriver? Explicit wait Fluent wait Types of Wait Implicit wait Implicit wait basically tells Selenium to wait for a certain amount of time before throwing a “No such element” exception. driver.manage().timeouts().implicitlyWait(TimeOut, TimeUnit.SECONDS);
Implicit wait Fluent wait 8 What are the types of waits supported by WebDriver? Types of Wait 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);
8 What are the types of waits supported by WebDriver? Implicit wait Explicit wait Types of Wait Fluent wait Fluent wait 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);
9 Mention the types of navigation commands
9 Mention the types of navigation commands driver.navigate().to("https://www.ebay.in/"); Navigates to the provided URL
9 Mention the types of navigation commands driver.navigate().to("https://www.ebay.in/"); Navigates to the provided URL driver.navigate().refresh(); This method Refresh the current page
9 Mention the types of navigation commands driver.navigate().to("https://www.ebay.in/"); Navigates to the provided URL driver.navigate().refresh(); This method Refresh the current page driver.navigate().forward(); This method does the same operation as clicking on the Forward Button of any browser. It neither accepts nor returns anything
9 Mention the types of navigation commands driver.navigate().to("https://www.ebay.in/"); Navigates to the provided URL driver.navigate().refresh(); This method Refresh the current page driver.navigate().back(); This method does the same operation as clicking on the Back Button of any browser. It neither accepts nor returns anything driver.navigate().forward(); This method does the same operation as clicking on the Forward Button of any browser. It neither accepts nor returns anything
What is the major difference between driver.close() and driver.quit()?10
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 10
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() If quit() is called on the driver instance and there are one or more browser windows open, it closes all the open browser windows 10
Intermediate level
11 How to type text in an input box using Selenium?
How to type text in an input box using Selenium? sendKeys() is the method used to type text in input boxes 11
How to type text in an input box using Selenium? sendKeys() is the method used to type text in input boxes Consider the following example WebElement email = driver.findElement(By.id(“email”)); email.sendKeys(“abcd.efgh@gmail.com”); WebElement password = driver.findElement(By.id(“Password”)); password.sendKeys(“abcdefgh123”); Finds the “email” text field using id locator 11
How to type text in an input box using Selenium? sendKeys() is the method used to type text in input boxes 11 Consider the following example WebElement email = driver.findElement(By.id(“email”)); email.sendKeys(“abcd.efgh@gmail.com”); WebElement password = driver.findElement(By.id(“Password”)); password.sendKeys(“abcdefgh123”); Enter text into the email address field
How to type text in an input box using Selenium? sendKeys() is the method used to type text in input boxes Finds the “password” text field using id locator 11 Consider the following example WebElement email = driver.findElement(By.id(“email”)); email.sendKeys(“abcd.efgh@gmail.com”); WebElement password = driver.findElement(By.id(“Password”)); password.sendKeys(“abcdefgh123”);
How to type text in an input box using Selenium? sendKeys() is the method used to type text in input boxes Enter text into the password field 11 Consider the following example WebElement email = driver.findElement(By.id(“email”)); email.sendKeys(“abcd.efgh@gmail.com”); WebElement password = driver.findElement(By.id(“Password”)); password.sendKeys(“abcdefgh123”);
12 How to click on a hyperlink in Selenium?
12 How to click on a hyperlink in Selenium? driver.findElement(By.linkText(“Today’s deals”)).click(); The command finds the element using link text and then clicks on that element and thus the user would be re-directed to the corresponding page
12 How to click on a hyperlink in Selenium? driver.findElement(By.linkText(“Today’s deals”)).click(); The command finds the element using link text and then clicks on that element and thus the user would be re-directed to the corresponding page driver.findElement(By.partialLinkText(“Service”)).click(); The above command finds the element based on the substring of the link provided in the parenthesis and thus partialLinkText() finds the web element
13 How to scroll down a page using JavaScript?
13 How to scroll down a page using JavaScript? scrollBy() method is used to scroll down the webpage General syntax: executeScript("window.scrollBy(x-pixels,y-pixels)");
13 First create a JavaScript object JavascriptExecutor js = (JavascriptExecutor) driver; scrollBy() method is used to scroll down the webpage General syntax: executeScript("window.scrollBy(x-pixels,y-pixels)"); How to scroll down a page using JavaScript?
13 First create a JavaScript object JavascriptExecutor js = (JavascriptExecutor) driver; Launch the desired application driver.get(“https://www.amazon.com”); scrollBy() method is used to scroll down the webpage General syntax: executeScript("window.scrollBy(x-pixels,y-pixels)"); How to scroll down a page using JavaScript?
13 First create a JavaScript object JavascriptExecutor js = (JavascriptExecutor) driver; Launch the desired application driver.get(“https://www.amazon.com”); Scroll down to the desired location js.executeScript("window.scrollBy(0,1000)"); scrollBy() method is used to scroll down the webpage General syntax: executeScript("window.scrollBy(x-pixels,y-pixels)"); The window is scrolled vertically by 1000 pixels How to scroll down a page using JavaScript?
14 How to assert the title of a webpage?
14 How to assert the title of a webpage? Get the title of the webpage and store in a variable String actualTitle = driver.getTitle(); Type in the expected title String expectedTitle = “abcdefgh"; Verify if both of them are equal if(actualTitle.equalsIgnoreCase(expectedTitle)) System.out.println("Title Matched"); else System.out.println("Title didn't match"); Alternatively, Assert.assertEquals(actualTitle, expectedTitle);
15 How to mouse hover over a web element?
15 How to mouse hover over a web element? Actions class utility is used to hover over a web element in Selenium WebDriver
15 How to mouse hover over a web element? Actions class utility is used to hover over a web element in Selenium WebDriver Instantiate Actions class Actions action = new Actions(driver); In this scenario we hover over search box of a website actions.moveToElement(driver.findElement(By.id("id of the searchbox"))).perform();
16 How to retrieve CSS properties of an element?
16 How to retrieve CSS properties of an element? getCssValue() method is used to retrieve CSS properties of any web element
16 How to retrieve CSS properties of an element? getCssValue() method is used to retrieve CSS properties of any web element General Syntax: driver.findElement(By.id(“id“)).getCssValue(“name of css attribute”); Example: driver.findElement(By.id(“email“)).getCssValue(“font-size”);
17 What is POM (Page Object Model)?
17 What is POM (Page Object Model)? Page Object Model is a design pattern that helps create object repositories for the web elements Every webpage of the application has a corresponding page class that is responsible for locating the web elements and performing actions on them POM improves code re-usability and readability. Multiple test cases can be run on the object repository
18 Can Captcha be automated?
18 Can Captcha be automated? Captcha is a security feature that prevents bots and automated programs from accessing sensitive information No, Selenium cannot automate Captcha Automation test engineer has to manually type the captcha while other fields can be filled automatically
19 How does Selenium handle Windows based pop-ups?
19 How does Selenium handle Windows based pop-ups? Selenium was designed to handle web applications. 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
20 How to take screenshots in WebDriver?
20 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 File scrFile = ((TakeScreenshot)driver).getScreenshotAs(outputType.FILE);
Advanced level
21 Can you type in a textbox without using sendKeys()?
21 Can you type in a textbox without using sendKeys()? Yes! Text can be entered into a textbox using JavaScriptExecutor
21 Can you type in a textbox without using sendKeys()? Yes! Text can be entered into a textbox using JavaScriptExecutor JavascriptExecutor jse = (JavascriptExecutor) driver; jse.executeScript("document.getElementById(‘email').value=“abc.efg@xyz.com”);
22 How to select a value from a dropdown in Selenium WebDriver?
22 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
22 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 parameter to its constructor. WebElement testDrop = driver.findElement(By.id("testingDropdown")); Select dropdown = new Select(testDrop);
22 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 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 dropdow,.selectByVisibleText(“The Alchemist”);
23 What does the switchTo() command do?
23 What does the switchTo() command do? switchTo() command is used to switch between windows, frames or pop-ups within the application. Every window instantiated by the WebDriver is given a unique alphanumeric value called “Window Handle”
23 What does the switchTo() command do? Get the window handle of the window you wish to switch to String handle= driver.getWindowHandle(); Switch to the desired window driver.switchTo().window(handle); Alternatively for(String handle= driver.getWindowHandles()) { driver.switchTo().window(handle); } switchTo() command is used to switch between windows, frames or pop-ups within the application. Every window instantiated by the WebDriver is given a unique alphanumeric value called “Window Handle”
24 How to upload a file in Selenium WebDriver?
24 How to upload a file in Selenium WebDriver? Using sendkeys() or Robot class method, we could easily achieve this. Locate the text box and set the file path using sendkeys() and click on submit button
24 How to upload a file in Selenium WebDriver? Locate the browse button WebElement browse =driver.findElement(By.id("uploadfile")); Pass the path of the file to be uploaded using sendKeys method browse.sendKeys("D:SeleniumInterviewUploadFile.txt"); Using sendkeys() or Robot class method, we could easily achieve this. Locate the text box and set the file path using sendkeys() and click on submit button
25 How to set browser window size in WebDriver?
25 How to set browser window size in WebDriver? The window size can be maximized, set or resized
25 How to set browser window size in WebDriver? The window size can be maximized, set or resized To maximize the window driver.manage().window().maximize(); To set the window size Dimension d = new Dimension(400,600); driver.manage().window().setSize(d); Alternatively, Window size can be reset using JavaScriptExecutor ((JavascriptExecutor)driver).executeScript("window.resizeTo(1024, 768)");
26 When do we use findElement() and findElements()?
26 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. General syntax: WebElement element = driver.findElement(By.id(example));
26 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. General syntax: WebElement element = driver.findElement(By.id(example)); findElements() is used to find all the elements in the current web page matching to the specified locator value. All the matching elements would be fetched and stored in the list of Web elements. General syntax: List <WebElement> elementList = driver.findElements(By.id(example));
27 What is pause on exception in Selenium IDE?
27 What is pause on 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
27 What is pause on exception in Selenium 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
28 How to login into any site if it is showing an Authentication Pop-Up for Username and Password?
28 How to login into any site if it is showing an Authentication Pop-Up for Username and Password?
28 How to login into any site if it is showing an Authentication Pop-Up for Username and Password? Use the explicit wait command WebDriverWait wait = new WebDriverWait(driver, 10); Alert class is used to verify the alert Alert alert = wait.until(ExpectedConditions.alertIsPresent()); Once verified, provide the credentials alert.authenticateUsing(new UserAndPassword(<username>, <password>)); To handle authentication pop-ups, we first verify its appearance and then handle them using explicit wait command
29 What is the difference between single and double slash in Xpath?
29 What is the difference between single and double slash in Xpath? Single slash is used to create Xpath with absolute path i.e. the xpath would be created to start selection from the start node. /html/body/div[2]/div[1]/div[1]/a
29 What is the difference between single and double slash in Xpath? Single slash is used to create Xpath with absolute path i.e. the xpath would be created to start selection from the start node. /html/body/div[2]/div[1]/div[1]/a Double slash is used to create Xpath with relative path i.e. the xpath would be created to start selection from anywhere within the document //div[class="qa-logo"]/a
30 How do you find broken links in Selenium WebDriver?
30 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 200 – OK denotes that the link is working and it has been obtained. If any other status is obtained, then it is an indication that the link is broken. Some of the HTTP status codes are : • 200 – valid Link • 404 – Link Not Found • 400 – Bad Request • 401 – Unauthorized • 500 – Internal error We first obtain the links from the web application and individually get their status.
30 How do you find broken links in Selenium WebDriver? Navigate to the interested webpage for e.g. www.amazon.com Collect all the links from the webpage. All the links are associated with the Tag ‘a‘ List<WebElement> links = driver.findElements(By.tagName("a")); Create a list of type WebElement to store all the Link elements in to it. for(int i=0; i<links.size(); i++) { WebElement element = links.get(i); String url=element.getAttribute("href"); verifyLink(url); }
30 How do you find broken links in Selenium WebDriver? Now Create a Connection using URL object( i.e ., link) URL link = new URL(urlLink); Connect using Connect Method HttpURLConnection httpConn =(HttpURLConnection)link.openConnection(); Use getResponseCode () to get response code if(httpConn.getResponseCode()!== 200) Through exception if any error occurred System.out.println(“Broken Link”);
Selenium Interview Questions And Answers | Selenium Interview Questions | Selenium | Simplilearn

Selenium Interview Questions And Answers | Selenium Interview Questions | Selenium | Simplilearn

  • 2.
  • 3.
    1 What arethe Selenium suite components?
  • 4.
    1 What arethe Selenium suite components? Selenium suite Selenium IDE It is a Firefox/Chrome plug-in that was developed to speed up the creation of automation scripts. It records the user actions on the web browser and exports them as a reusable script
  • 5.
    1 What arethe Selenium suite components? Selenium suite Selenium Remote Control (RC) RC is a server that allows users to write application tests in various programming languages. The commands from the test script are accepted by this server and are sent to the browser as Selenium core JavaScript commands. The browser then behaves accordingly
  • 6.
    1 What arethe Selenium suite components? Selenium suite Selenium WebDriver WebDriver is a programming interface that helps create and run test cases. It makes provision to act on web elements. Unlike RC, WebDriver does not require an additional server and interacts natively with the browser applications
  • 7.
    1 What arethe Selenium suite components? Selenium suite Selenium Grid Grid was designed to distribute commands to different machines simultaneously. It allows the parallel execution of tests on different browsers and different operating systems. It is exceptionally flexible and is integrated with other suite components for simultaneous execution
  • 8.
    2 What arethe limitations of Selenium?
  • 9.
    2 What arethe limitations of Selenium? No reliable tech support
  • 10.
    2 What arethe limitations of Selenium? No reliable tech support Tests only web applications
  • 11.
    2 What arethe limitations of Selenium? No reliable tech support Limited support for image testing Tests only web applications
  • 12.
    What are thelimitations of Selenium? No reliable tech support Limited support for image testing No built in reporting facility 2 Tests only web applications
  • 13.
    What are thelimitations of Selenium? No reliable tech support Limited support for image testing Tests only web applications No built in reporting facility Limited test management 2
  • 14.
    What are thelimitations of Selenium? No reliable tech support Limited support for image testing No built in reporting facility Limited test management May require knowledge of programming languages 2 Tests only web applications
  • 15.
    3 What arethe testing types supported by Selenium?
  • 16.
    3 What arethe testing types supported by Selenium? Selenium supports Regression testing and Functional testing
  • 17.
    3 What arethe testing types supported by Selenium? Selenium supports Regression testing and Functional testing Regression testing Re-testing Prioritization of test cases Regression test selection Regression Testing is a full or partial selection of already executed test cases which are re-executed to ensure existing functionalities work fine. Steps involved are…
  • 18.
    3 What arethe testing types supported by Selenium? Selenium supports Regression testing and Functional testing Regression testing Re-testing Prioritization of test cases Regression test selection Regression Testing is a full or partial selection of already executed test cases which are re-executed to ensure existing functionalities work fine. Steps involved are… • All tests in the existing test suite are executed • Very expensive and time consuming
  • 19.
    3 What arethe testing types supported by Selenium? Selenium supports Regression testing and Functional testing Regression Testing is a full or partial selection of already executed test cases which are re-executed to ensure existing functionalities work fine Steps involved are… Regression testing Re-testing Prioritization of test cases Regression test selection Tests are classified as • Feature tests • Integration tests • End to End tests Some of these tests are selected
  • 20.
    3 What arethe testing types supported by Selenium? Selenium supports Regression testing and Functional testing Regression Testing is a full or partial selection of already executed test cases which are re-executed to ensure existing functionalities work fine Steps involved are… Regression testing Re-testing Prioritization of test cases Regression test selection The selected test cases are prioritized based on business impact and critical functionalities
  • 21.
    3 What arethe testing types supported by Selenium? Selenium supports Regression testing and Functional testing Functional Testing involves the verification of every function of the application with the required specification. Identify test input Compute test outcome Execute test Compare the test outcome with the actual outcome Functional testing
  • 22.
    4 What areSelenium 2.0 and Selenium 3.0?
  • 23.
    4 Selenium 2.0 isa tool that makes the development of automated tests for web applications easier. It represents the merger of the original Selenium project with the WebDriver project. Selenium RC got deprecated since the merge, however was used for backward compatibility. Selenium 2 Selenium IDE Selenium RC Grid Selenium WebDriver What are Selenium 2.0 and Selenium 3.0?
  • 24.
    4 Selenium 2.0 isa tool that makes the development of automated tests for web applications easier. It represents the merger of the original Selenium project with the WebDriver project. Selenium RC got deprecated since the merge, however was used for backward compatibility. Selenium 2 Selenium IDE Selenium RC Grid Selenium WebDriver Selenium 3 Selenium IDE Selenium WebDriver Grid Selenium 3.0 is the extended version of Selenium 2.0. It is inherently backward compatible and does not involve Selenium RC. The new version came along with several bug fixes and increased stability. What are Selenium 2.0 and Selenium 3.0?
  • 25.
    5 What isSame Origin policy? How is it handled?
  • 26.
    5 What isSame Origin policy? 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
  • 27.
    5 What isSame Origin policy? 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 Origin is a combination of URL scheme, hostname and port number. Same Origin policy prevents a malicious script on one page to access sensitive data on another webpage
  • 28.
    5 What isSame Origin policy? 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 Consider a JavaScript program used by google.com. This test application can access all Google domain pages like google.com/login, google.com/mail, etc.
  • 29.
    5 What isSame Origin policy? 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 However, it cannot access pages from other domains like yahoo.com
  • 30.
    5 What isSame Origin policy? How is it handled? Selenium RC was introduced to address this. The server acts as a client configured HTTP proxy and "tricks" the browser into believing that Selenium Core and the web application being tested come from the same origin. RC server 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 Test script
  • 31.
    6 What isSelenese? How is it classified?
  • 32.
    6 What isSelenese? How is it classified? Selenese is the set of Selenium commands which are used to test your web application. Tester can test the broken links, existence of some object on the UI, Ajax functionality, alerts, window, list options and lot more using Selenese
  • 33.
    6 What isSelenese? How is it classified? Selenese is the set of Selenium commands which are used to test your web application. Tester can test the broken links, existence of some object on the UI, Ajax functionality, alerts, window, list options and lot more using Selenese Action Accessors Assertions Commands which interact directly with the application Allow the user to store certain values to a user-defined variable Verifies the current state of the application with an expected state Selenium commands
  • 34.
    7 Mention thetypes of web locators.
  • 35.
    7 Mention thetypes of web locators. Locator is a command that tells Selenium IDE which GUI elements ( say Text Box, Buttons, Check Boxes etc) it needs to operate on. Locators specify the area of action
  • 36.
    7 Mention thetypes of web locators. Locator is a command that tells Selenium IDE which GUI elements ( say Text Box, Buttons, Check Boxes etc) it needs to operate on. Locators specify the area of action Locator by ID: It takes a parameter of String which is a Value of ID attribute and it returns the object to findElement() method. driver.findElement(By.id(“user”)); Locator by link: If your targeted element is link text then you can use by link text element locator to locate that element driver.findElement(By.linkText(“Today’s deals”)).click(); Locator by Partial link: The target link can be located using a portion of text in a link text element. driver.findElement(By.linkText(“Service”)).click(); Locator by Name: The first element with the name attribute value matching the location will be returned driver.findElement(By.name(“books”).click());
  • 37.
    7 Mention thetypes of web locators. Locator is a command that tells Selenium IDE which GUI elements ( say Text Box, Buttons, Check Boxes etc) it needs to operate on. Locators specify the area of action Locator by TagName: Locates all the elements with the matching tag name driver.findElement(By.tagName(“button”).click()); Locator by classname: This finds elements based on the value of the CLASS attribute. If an element has many classes then this will match against each of them. driver.findElement(By.className(“inputtext”)); Locator by XPath: It takes a parameter of String which is a XPATHEXPRESSION and it returns an object to findElement() method driver.findElement(By.xpath(“//span[contains(text(),’an account’)]”)).getText(); Locator by CSS Selector: Locates elements based on the driver’s underlying CSS selector engine. driver.findElement(By.cssSelector(“input#email”)).sendKeys(“myemail@email.com”);
  • 38.
    8 What arethe types of waits supported by WebDriver?
  • 39.
    8 What arethe types of waits supported by WebDriver? Explicit wait Fluent wait Types of Wait Implicit wait Implicit wait basically tells Selenium to wait for a certain amount of time before throwing a “No such element” exception. driver.manage().timeouts().implicitlyWait(TimeOut, TimeUnit.SECONDS);
  • 40.
    Implicit wait Fluentwait 8 What are the types of waits supported by WebDriver? Types of Wait 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);
  • 41.
    8 What arethe types of waits supported by WebDriver? Implicit wait Explicit wait Types of Wait Fluent wait Fluent wait 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);
  • 42.
    9 Mention thetypes of navigation commands
  • 43.
    9 Mention thetypes of navigation commands driver.navigate().to("https://www.ebay.in/"); Navigates to the provided URL
  • 44.
    9 Mention thetypes of navigation commands driver.navigate().to("https://www.ebay.in/"); Navigates to the provided URL driver.navigate().refresh(); This method Refresh the current page
  • 45.
    9 Mention thetypes of navigation commands driver.navigate().to("https://www.ebay.in/"); Navigates to the provided URL driver.navigate().refresh(); This method Refresh the current page driver.navigate().forward(); This method does the same operation as clicking on the Forward Button of any browser. It neither accepts nor returns anything
  • 46.
    9 Mention thetypes of navigation commands driver.navigate().to("https://www.ebay.in/"); Navigates to the provided URL driver.navigate().refresh(); This method Refresh the current page driver.navigate().back(); This method does the same operation as clicking on the Back Button of any browser. It neither accepts nor returns anything driver.navigate().forward(); This method does the same operation as clicking on the Forward Button of any browser. It neither accepts nor returns anything
  • 47.
    What is themajor difference between driver.close() and driver.quit()?10
  • 48.
    What is themajor 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 10
  • 49.
    What is themajor 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() If quit() is called on the driver instance and there are one or more browser windows open, it closes all the open browser windows 10
  • 50.
  • 51.
    11 How totype text in an input box using Selenium?
  • 52.
    How to typetext in an input box using Selenium? sendKeys() is the method used to type text in input boxes 11
  • 53.
    How to typetext in an input box using Selenium? sendKeys() is the method used to type text in input boxes Consider the following example WebElement email = driver.findElement(By.id(“email”)); email.sendKeys(“abcd.efgh@gmail.com”); WebElement password = driver.findElement(By.id(“Password”)); password.sendKeys(“abcdefgh123”); Finds the “email” text field using id locator 11
  • 54.
    How to typetext in an input box using Selenium? sendKeys() is the method used to type text in input boxes 11 Consider the following example WebElement email = driver.findElement(By.id(“email”)); email.sendKeys(“abcd.efgh@gmail.com”); WebElement password = driver.findElement(By.id(“Password”)); password.sendKeys(“abcdefgh123”); Enter text into the email address field
  • 55.
    How to typetext in an input box using Selenium? sendKeys() is the method used to type text in input boxes Finds the “password” text field using id locator 11 Consider the following example WebElement email = driver.findElement(By.id(“email”)); email.sendKeys(“abcd.efgh@gmail.com”); WebElement password = driver.findElement(By.id(“Password”)); password.sendKeys(“abcdefgh123”);
  • 56.
    How to typetext in an input box using Selenium? sendKeys() is the method used to type text in input boxes Enter text into the password field 11 Consider the following example WebElement email = driver.findElement(By.id(“email”)); email.sendKeys(“abcd.efgh@gmail.com”); WebElement password = driver.findElement(By.id(“Password”)); password.sendKeys(“abcdefgh123”);
  • 57.
    12 How toclick on a hyperlink in Selenium?
  • 58.
    12 How toclick on a hyperlink in Selenium? driver.findElement(By.linkText(“Today’s deals”)).click(); The command finds the element using link text and then clicks on that element and thus the user would be re-directed to the corresponding page
  • 59.
    12 How toclick on a hyperlink in Selenium? driver.findElement(By.linkText(“Today’s deals”)).click(); The command finds the element using link text and then clicks on that element and thus the user would be re-directed to the corresponding page driver.findElement(By.partialLinkText(“Service”)).click(); The above command finds the element based on the substring of the link provided in the parenthesis and thus partialLinkText() finds the web element
  • 60.
    13 How toscroll down a page using JavaScript?
  • 61.
    13 How toscroll down a page using JavaScript? scrollBy() method is used to scroll down the webpage General syntax: executeScript("window.scrollBy(x-pixels,y-pixels)");
  • 62.
    13 First create aJavaScript object JavascriptExecutor js = (JavascriptExecutor) driver; scrollBy() method is used to scroll down the webpage General syntax: executeScript("window.scrollBy(x-pixels,y-pixels)"); How to scroll down a page using JavaScript?
  • 63.
    13 First create aJavaScript object JavascriptExecutor js = (JavascriptExecutor) driver; Launch the desired application driver.get(“https://www.amazon.com”); scrollBy() method is used to scroll down the webpage General syntax: executeScript("window.scrollBy(x-pixels,y-pixels)"); How to scroll down a page using JavaScript?
  • 64.
    13 First create aJavaScript object JavascriptExecutor js = (JavascriptExecutor) driver; Launch the desired application driver.get(“https://www.amazon.com”); Scroll down to the desired location js.executeScript("window.scrollBy(0,1000)"); scrollBy() method is used to scroll down the webpage General syntax: executeScript("window.scrollBy(x-pixels,y-pixels)"); The window is scrolled vertically by 1000 pixels How to scroll down a page using JavaScript?
  • 65.
    14 How toassert the title of a webpage?
  • 66.
    14 How toassert the title of a webpage? Get the title of the webpage and store in a variable String actualTitle = driver.getTitle(); Type in the expected title String expectedTitle = “abcdefgh"; Verify if both of them are equal if(actualTitle.equalsIgnoreCase(expectedTitle)) System.out.println("Title Matched"); else System.out.println("Title didn't match"); Alternatively, Assert.assertEquals(actualTitle, expectedTitle);
  • 67.
    15 How tomouse hover over a web element?
  • 68.
    15 How tomouse hover over a web element? Actions class utility is used to hover over a web element in Selenium WebDriver
  • 69.
    15 How tomouse hover over a web element? Actions class utility is used to hover over a web element in Selenium WebDriver Instantiate Actions class Actions action = new Actions(driver); In this scenario we hover over search box of a website actions.moveToElement(driver.findElement(By.id("id of the searchbox"))).perform();
  • 70.
    16 How toretrieve CSS properties of an element?
  • 71.
    16 How toretrieve CSS properties of an element? getCssValue() method is used to retrieve CSS properties of any web element
  • 72.
    16 How toretrieve CSS properties of an element? getCssValue() method is used to retrieve CSS properties of any web element General Syntax: driver.findElement(By.id(“id“)).getCssValue(“name of css attribute”); Example: driver.findElement(By.id(“email“)).getCssValue(“font-size”);
  • 73.
    17 What isPOM (Page Object Model)?
  • 74.
    17 What isPOM (Page Object Model)? Page Object Model is a design pattern that helps create object repositories for the web elements Every webpage of the application has a corresponding page class that is responsible for locating the web elements and performing actions on them POM improves code re-usability and readability. Multiple test cases can be run on the object repository
  • 75.
    18 Can Captchabe automated?
  • 76.
    18 Can Captchabe automated? Captcha is a security feature that prevents bots and automated programs from accessing sensitive information No, Selenium cannot automate Captcha Automation test engineer has to manually type the captcha while other fields can be filled automatically
  • 77.
    19 How doesSelenium handle Windows based pop-ups?
  • 78.
    19 How doesSelenium handle Windows based pop-ups? Selenium was designed to handle web applications. 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
  • 79.
    20 How totake screenshots in WebDriver?
  • 80.
    20 How totake screenshots in WebDriver? TakeScreenshot interface can be used to take screenshots in WebDriver. getScreenshotAs() method can be used to save the screenshot File scrFile = ((TakeScreenshot)driver).getScreenshotAs(outputType.FILE);
  • 81.
  • 82.
    21 Can youtype in a textbox without using sendKeys()?
  • 83.
    21 Can youtype in a textbox without using sendKeys()? Yes! Text can be entered into a textbox using JavaScriptExecutor
  • 84.
    21 Can youtype in a textbox without using sendKeys()? Yes! Text can be entered into a textbox using JavaScriptExecutor JavascriptExecutor jse = (JavascriptExecutor) driver; jse.executeScript("document.getElementById(‘email').value=“abc.efg@xyz.com”);
  • 85.
    22 How toselect a value from a dropdown in Selenium WebDriver?
  • 86.
    22 How toselect a value from a dropdown in Selenium WebDriver? Select class in WebDriver is used for selecting and deselecting options in a dropdown
  • 87.
    22 How toselect 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 parameter to its constructor. WebElement testDrop = driver.findElement(By.id("testingDropdown")); Select dropdown = new Select(testDrop);
  • 88.
    22 How toselect a value from a dropdown in Selenium WebDriver? Select class in WebDriver is used for selecting and deselecting options in a dropdown 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 dropdow,.selectByVisibleText(“The Alchemist”);
  • 89.
    23 What doesthe switchTo() command do?
  • 90.
    23 What doesthe switchTo() command do? switchTo() command is used to switch between windows, frames or pop-ups within the application. Every window instantiated by the WebDriver is given a unique alphanumeric value called “Window Handle”
  • 91.
    23 What doesthe switchTo() command do? Get the window handle of the window you wish to switch to String handle= driver.getWindowHandle(); Switch to the desired window driver.switchTo().window(handle); Alternatively for(String handle= driver.getWindowHandles()) { driver.switchTo().window(handle); } switchTo() command is used to switch between windows, frames or pop-ups within the application. Every window instantiated by the WebDriver is given a unique alphanumeric value called “Window Handle”
  • 92.
    24 How toupload a file in Selenium WebDriver?
  • 93.
    24 How toupload a file in Selenium WebDriver? Using sendkeys() or Robot class method, we could easily achieve this. Locate the text box and set the file path using sendkeys() and click on submit button
  • 94.
    24 How toupload a file in Selenium WebDriver? Locate the browse button WebElement browse =driver.findElement(By.id("uploadfile")); Pass the path of the file to be uploaded using sendKeys method browse.sendKeys("D:SeleniumInterviewUploadFile.txt"); Using sendkeys() or Robot class method, we could easily achieve this. Locate the text box and set the file path using sendkeys() and click on submit button
  • 95.
    25 How toset browser window size in WebDriver?
  • 96.
    25 How toset browser window size in WebDriver? The window size can be maximized, set or resized
  • 97.
    25 How toset browser window size in WebDriver? The window size can be maximized, set or resized To maximize the window driver.manage().window().maximize(); To set the window size Dimension d = new Dimension(400,600); driver.manage().window().setSize(d); Alternatively, Window size can be reset using JavaScriptExecutor ((JavascriptExecutor)driver).executeScript("window.resizeTo(1024, 768)");
  • 98.
    26 When dowe use findElement() and findElements()?
  • 99.
    26 When dowe 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. General syntax: WebElement element = driver.findElement(By.id(example));
  • 100.
    26 When dowe 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. General syntax: WebElement element = driver.findElement(By.id(example)); findElements() is used to find all the elements in the current web page matching to the specified locator value. All the matching elements would be fetched and stored in the list of Web elements. General syntax: List <WebElement> elementList = driver.findElements(By.id(example));
  • 101.
    27 What ispause on exception in Selenium IDE?
  • 102.
    27 What ispause on 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
  • 103.
    27 What ispause on exception in Selenium 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
  • 104.
    28 How to logininto any site if it is showing an Authentication Pop-Up for Username and Password?
  • 105.
    28 How to logininto any site if it is showing an Authentication Pop-Up for Username and Password?
  • 106.
    28 How to logininto any site if it is showing an Authentication Pop-Up for Username and Password? Use the explicit wait command WebDriverWait wait = new WebDriverWait(driver, 10); Alert class is used to verify the alert Alert alert = wait.until(ExpectedConditions.alertIsPresent()); Once verified, provide the credentials alert.authenticateUsing(new UserAndPassword(<username>, <password>)); To handle authentication pop-ups, we first verify its appearance and then handle them using explicit wait command
  • 107.
    29 What isthe difference between single and double slash in Xpath?
  • 108.
    29 What isthe difference between single and double slash in Xpath? Single slash is used to create Xpath with absolute path i.e. the xpath would be created to start selection from the start node. /html/body/div[2]/div[1]/div[1]/a
  • 109.
    29 What isthe difference between single and double slash in Xpath? Single slash is used to create Xpath with absolute path i.e. the xpath would be created to start selection from the start node. /html/body/div[2]/div[1]/div[1]/a Double slash is used to create Xpath with relative path i.e. the xpath would be created to start selection from anywhere within the document //div[class="qa-logo"]/a
  • 110.
    30 How doyou find broken links in Selenium WebDriver?
  • 111.
    30 How doyou 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 200 – OK denotes that the link is working and it has been obtained. If any other status is obtained, then it is an indication that the link is broken. Some of the HTTP status codes are : • 200 – valid Link • 404 – Link Not Found • 400 – Bad Request • 401 – Unauthorized • 500 – Internal error We first obtain the links from the web application and individually get their status.
  • 112.
    30 How doyou find broken links in Selenium WebDriver? Navigate to the interested webpage for e.g. www.amazon.com Collect all the links from the webpage. All the links are associated with the Tag ‘a‘ List<WebElement> links = driver.findElements(By.tagName("a")); Create a list of type WebElement to store all the Link elements in to it. for(int i=0; i<links.size(); i++) { WebElement element = links.get(i); String url=element.getAttribute("href"); verifyLink(url); }
  • 113.
    30 How doyou find broken links in Selenium WebDriver? Now Create a Connection using URL object( i.e ., link) URL link = new URL(urlLink); Connect using Connect Method HttpURLConnection httpConn =(HttpURLConnection)link.openConnection(); Use getResponseCode () to get response code if(httpConn.getResponseCode()!== 200) Through exception if any error occurred System.out.println(“Broken Link”);