Selenium Interview Questions part 1

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

How do you handle dynamic elements?

● Find the static part of the id and write a locator(xpath or css) --> And then use Startswith, contains, EndsWith ● contains( ) --> //*[contains(@name=`btn`)] ● startwith( ) --> //label[startwith(@id, `message`)] ● text( ) --> //td[text() = `usedId`] ● or & and --> //input[@type = `submit` AND @name = `login`]

What is the key class in Selenium?

● Gives us option for pressing keys from keyboard ● Key.ENTER ● MUST BE PASSED TO SendKeys() method ● Ex; .sendkeys("charger" + keys.ENTER)

What are various ways of locating an element in Selenium?

● Id ● Name ● ClassName ● Xpath ● CSS ● LinkText ● PartialLinkText ● TagName

How do you handle js alerts?

● If the alert on the browser comes from JavaScript, we use the Alert class. ○ Alert alert = driver.switchTo.alert(); ■ alert.accept(); ■ alert.dismiss(); ■ alert.sendKeys(); ■ alert.getText();

How to handle multiple frames?

● If there are 4 frames, you have to go through each from consecutively to reach a certain frame. Can't jump to the 3rd frame from 1st frame.

Implicit Wait vs Explicit Wait?

● Implicit wait is a wait which waits for a specified time while locating an element before throwing "NoSuchElementException". As by default selenium tries to find elements immediately without any wait. So, it is good to use implicit wait. This wait applied to all elements of the current driver instance. ● Explicit wait is a wait which is applied to a particular webelement until the ExpectedCondition specified is met. ● Implicit wait is simply; if condition is met before the timeout, it will continue to next step, if condition is not met within timeout throw "No Such Element" exception. ● Explicit wait sometimes we need to wait for a certain event/condition such as element is visible, clickable, enabled.... ●driver.manage().timeouts().implicitlyWait(5,TimeUnit.SECONDS); webDriverWait wait = new WebDriverWait (driver, 5);wait.until (ExpectedConditions.visibilityOf(element);

What is framework?

● In test automation, framework is the blueprint of test automation. ● It includes your folder structures, where to save you function library, test results, test data, resources. ● It is essential because when you are working on automation project everyone will have a guideline to follow and our script will be easier to maintain.

Why can't I find the element?

● Locator changed ● There is an iframe ● Waiting time:: page is loading slowly or Element is dynamic:: locator ● Page is not fully loaded/opened ● Page changes and that element does not exist anymore

What we don't do with selenium?

● Performance, load, stress testing (These tests are done by experts trained in these tools) ● Pure database testing (if we only test the DB itself), ● Unit tests..., look and feel based testing (color, shapes, etc.), ● static testing

What are the advantages of Selenium?

● Selenium is open source and free to use without any licensing cost ● It supports multiple languages like Java, Ruby, Python, C#... ● It supports multi-browser testing ● It has a good amount of resources and helping community ● It supports many operating systems like Windows, Mac, Linux ... ● Interact with the web application

What are the disadvantages of Selenium?

● Selenium supports only web-based applications, does not support windows-based application ● No built-in reporting tool, it needs third party tools for report generation activity ● Cannot work with graphics, captchas, barcodes, shapes ● It does not support file upload facility ● Hard to master, requires developer level knowledge ● Hard to write good locators ● Hard to synchronize

What is Thread.sleep()?

● Slows down selenium to catch up ● Throws exception so must handle it or throw it

Absolute (/) and Relative (//) Xpath?

● Syntax --> //tagname[@attribute=`value`] ● Absolute xpath starts with a single slash ( / ), starting from root element and all the way to the element. ● Relative xpath starts with double slash ( // ), starting selection matching anywhere in the document.

How can we move to the nth child element using xpath?

● There are two ways: ○ using square brackets with index position ■ For ex: div[2] will find the second div element ○ using position ( ) method ■ For ex: div[position()=2] will find the second div element

What if there is a dynamic popup that comes up randomly?

● Use try/catch with alert

How can we move to parent element using xpath?

● Using (..) expression in xpath, we can move to parent element

What are the limitations of Selenium?

● We cannot test desktop application ● We cannot test web services ● We have to use external libraries and tools for performing tasks like testing framework (TestNG, JUnit), reading from external files (Apache POI for excel) ● Automating Captcha is not possible using Selenium ● It does not support file upload facility

What is Selenium WebDriver?

● WebDriver (2.0); is a web automation framework and allows you to execute your tests in different browsers. (2011)

What is fluentWait?

● With Fluent wait you can set how frequently Selenium should check back if condition is not met. It is done with parameter PollingEvery. ● Subtype of explicit wait but you can override the conditions ● Wait<WebDriver>wait=newFluentWait<Webdriver>(driver).withTimout(5,timeUnit. seconds).pollingEvery(100,timeunit.milliseconds).ignoring(NoSuchElementExcep tion.class);

Difference between xpath and css selector?

● With xpath, we can search elements backward or forward, while css works only in forward direction ● Xpath can work with text, css cannot work ● Xpath has more combination and can search by index, css cannot search by index, but css is working faster than xpath

What is Xpath?

● Xpath is used to find the location of any element on a webpage using html structure. ● We could navigate through elements and attributes in an XML document to locate web Elements such as textbox, button, checkbox, Image ext... in webPage

Difference between close() and quit() command?

● driver.close() --> used to close the current browser ● driver.quit() --> used to close all the browser instances

What is the difference between driver.get() and driver.navigateto()?

● driver.get() --> To open an URL and it will wait till the whole page gets loaded ● driver.navigateto() --> To navigate to an URL and it will not wait till the whole page get loaded

How to maximize a web page?

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

What types of testing do you automate with Selenium?

● functional tests (positive/negative, UI) ● smoke tests ● regression tests ● integration tests ● end to end testing ● data driven


Ensembles d'études connexes

MKTG Chapter 1, MKTG Chapter 5, MKT 230 - chp. 5

View Set

Programming Fundamental quiz 1-4

View Set

Exam 3- Principles of Microeconomics (Spring 2018)

View Set