Selenium Interview Questions


1.       What is Selenium?

Selenium is a portable software-testing framework for web applications. It is an open-source tool and is mainly used for functional testing and regression testing. Since it is open-source, there is no licensing cost involved, which is a major advantage over other testing tools.


2.       Can you list down the different forms of Selenium?


Selenium WebDriver

Selenium Grid

Selenium IDE

Selenium RC (Depreciated now)



3.       What is selenium web driver?


It provides a programming interface to design, maintain and execute test cases. Test were written to identify web elements on web pages and perform desired actions. It is faster because it makes direct calls to the browser.

Test execution can be performed on different browser with help of drivers, Below are the list of web drivers available in market.

a)       Firefox Driver (Gecko Driver)

b)       Chrome Driver

c)       Internet Explorer Driver

d)       Edge Driver

e)       Safari Driver

f)        Html Unit (Headless browser)



4.       Pros of Selenium WebDriver?

Supports major programming languages like Java, JavaScript, Ruby, Python, C#, PHP and Perl
Supports browsers like: Firefox, Chrome, IE, Safari, Edge Browser etc.,
Operating systems independent. Test can be performed on Windows, Mac, Linux, Android, iOS



5.       Cons of Selenium WebDriver?

Test of Images in not possible.

Cannot perform GUI testing and validate Object alignments of different browsers.

Cannot validate Desktop based applications

Cannot test web services using Selenium

Inbuild Reporting tools are not integrated. Need to rely on different reports like TestNg, log4J etc.,



6.       What are various ways of locating an element in selenium?


The different locators in selenium are- Id, XPath, CSSSelector, className, tagName, name, linkText, partialLinkText.



7.       What is an XPath?


Ans. The Extensible Markup Language (XML) is the context in which the XML Path Language, XPath, exists. It is query language for selecting nodes from XML documents. XPath is one of the locators supported by selenium webdriver to identify elements on web browser.



8.       What is CSS selector?


CSS stands for Cascading Style Sheet and is used by web pages to help keep information in the proper display format. It relies on pattern matching rules to determine which style applies to which element in the document. These patterns are called selectors and they range from tag names (for example, a to match links) to very complicated patterns that match very specific parts of a document.



9.      What is the difference between absolute and relative xpaths?


Absolute Xpath: It uses Complete path from the Root Element to the desire element. Single slash is used for creating XPaths with absolute paths beginning from root node.

                                Eg: /html/body/div[1]/table[2]/tr[2]/span[1]

Relative Xpath: You can simply start by referencing the element you want and go from there. Double slash is used for creating relative XPaths

                                Eg: .//*[@id='answers']/tr[1]/span[1]



10.   What is the syntax to create Web driver instance?


For creating firefox webdriver instance below syntax is used.

System.setProperty("webdriver.gecko.driver", <Path of the firefox driver>);

WebDriver driver= new FirefoxDriver();



11.   What is the difference between driver.get() and driver.navigate.to()?


driver.get() : It's used to go to the particular website , But it doesn't maintain the browser History and cookies so , we can't use forward and backward button , if we click on that , page will not get schedule

driver.navigate() : it's used to go to the particular website , but it maintains the browser history and cookies, so we can use forward and backward button to navigate between the pages during the coding of Testcase



12.   What is the difference between implicit and explicit wait in selenium?


Implicit Wait - It instructs the web driver to wait for some time by poll the DOM. Once you declared implicit wait it will be available for the entire life of web driver instance. By default the value will be 0. If you set a longer default, then the behavior will poll the DOM on a periodic basis depending on the browser/driver implementation.


Syntax: driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);


Explicit Wait for ExpectedConditions - It is the custom one. It is intelligent waits that are confined to a particular web element. Using explicit waits, you are basically asking WebDriver to wait until max wait time for X units of time before it gives up.


Syntax

WebDriverWait wait = new WebDriverWait(driver, 10);

wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("locator")));

Few other explicit conditions are

textToBePresentInElementLocated, titleContains, alertIsPresent, elementToBeClickable, stalenessOf, visibilityOf, visibilityOfElementLocated, invisibilityOfElementLocated etc.,



13.   What is the syntax to create WebElement via Selenium Webdriver?


WebElement element = driver.findElement(By.cssSelector("locator"));



14.   Count the number of elements on a page?


List<WebElement> element = driver.findElements(By.cssSelector("locator"));

Element.size(); // provide the no of elements on the page for a given locator.

This can be used to find out how many links are available on application.



15.   How to perform mouse hover an element via selenium webdriver?


Actions action = new Actions(driver);

WebElement element= driver.findElement(By.cssSelector("locator"));

action.moveToElement(element).perform();



16.   How to scroll to the element displayed below on the webpage via selenium web driver?


WebElement element = driver.findElement(By.cssSelector("locator"));

Actions builder = new Actions(driver);

 ((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", element);



17.   Check if a check-box or a radio button is selected via webdriver?


driver.findElement(By.cssSelector("locator")).isSelected();



18.   How to perform right click on webelement via selenium webdriver?


Actions action = new Actions(driver);

WebElement element= driver.findElement(By.cssSelector("locator"));

action.contextClick(element).perform();


19.   How to drag elements on webpage via webdriver?


WebElement dragFrom = driver.findElement(By.cssSelector("Dragfrom_locator"));

WebElement dragTo = driver.findElement(By.cssSelector("Dragto_locator "));

Actions builder = new Actions(driver);

builder.clickAndHold(dragFrom).moveToElement(dragTo).release(dragTo).build().perform();

20.   Check if an element is visible on the page?


driver.findElement(By.cssSelector("locator")).isDisplayed();




21.   How to get the Browser title via Selenium webdriver?



driver.getTitle();

22.   Check if a button is enabled on the page?


driver.findElement(By.cssSelector("locator")).isEnabled();



23.   How to enter text in a textbox element using webdriver?


driver.findElement(By.cssSelector("locator")). sendKeys(“Entering UserName”);



24.   How can we clear a text written in a textbox?


Solution 1: driver.findElement(By.cssSelector("locator")).clear();

In case if clear doesn’t work then below code will help to clear the text.
Solution 2:

WebElement ele_clear = driver.findElement(By.cssSelector("locator"));

ele_clear.sendKeys(Keys.CONTROL + "a");

ele_clear.sendKeys(Keys.DELETE);


25.   How to get the current URL of the browser via Selenium webdriver?


driver.getCurrentUrl();



26.   How can we read element text displayed on an element via webdriver?


driver.findElement(By.cssSelector("locator")).getText();



27.   How to maximize browser window via selenium webdriver?


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



28.   How to delete cookies in webdriver?


driver.manage().deleteAllCookies();



29.   How to perform full screen for the browser via Selenium webdriver?


driver.manage().window().fullscreen();



30.   How can retrieve attributes values of webelement?


driver.findElement(By.cssSelector("locator")).getAttribute("AttributeNamecomeshere");


2 comments:

  1. Automation Testing Interview: Selenium Interview Questions >>>>> Download Now

    >>>>> Download Full

    Automation Testing Interview: Selenium Interview Questions >>>>> Download LINK

    >>>>> Download Now

    Automation Testing Interview: Selenium Interview Questions >>>>> Download Full

    >>>>> Download LINK Ks

    ReplyDelete

Different Types of Keyboard Inputs : Type, SendKeys & Device Replay

1. Most objects support the TYPE method.  Type will enter the specified string into an object or perform a certain keyboard combinat...