Selenium Testing

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

How to delete Browser Cookies with Selenium Web Driver?

driver.Manage().Cookies.DeleteAllCookies();

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

driver.close(): To close current WebDriver instance -------------------------------------------------------------- driver.quit(): To close all the opened WebDriver instances

How to press the ENTER key on text box In Selenium WebDriver? How to press TAB key in Selenium?

driver.findElement(By.id("Value")).sendKeys(Keys.ENTER); or driver.findElement(By.id("Value")).sendKeys(Keys.TAB);

What is the difference between Absolute Path and Relative Path?

- Absolute XPath starts from the root node and ends with desired descendant element's node. It starts with top HTML node and ends with input node. It stars single slash (/) - Relative XPath starts from any node in between the HTML page to the current element's node(last node of the element). It starts with a double forward slash(//)

What is the difference between Assert and Verify in Selenium?

- Assert: if the assert condition is true then the program control will execute the next test step but if the condition is false, the execution will stop and further test step will NOT be executed. ------------------------------------------------------------ - Verify: There won't be any halt in the test execution even though the verify condition is true or false.

How To Highlight Element Using Selenium WebDriver?

- By using JavascriptExecutor interface, we could highlight the specified element

How to clear the text in the text box using Selenium WebDriver?

- By using clear() method for example: driver.findElement(By.id("element")).clear();

How to get an attribute value using Selenium WebDriver?

- By using getAttribute(value); - It returns the value of the attribute passed as a parameter. String innerText = driver.findElement(By.cssSelector("div.success")).getAttribute("value");

How to pause a test execution for 5 seconds at a specific point?

- By using java.lang.Thread.sleep(long milliseconds) method. - Thread.sleep(5000)

How to input text in the text box using Selenium WebDriver?

- By using sendKeys() method for example: driver.findElement(By.xpath("//*[@attribute='value']")).sendKeys("some text");

Why do companies prefer Selenium Automation Tool?

- Free and open source - Have large user base and helping communities. - It allows multi-browser testing - It supports Multiple programming languages (Java, ruby, python, Php etc. - Parallel Execution is possible (selenium grid)

What are the types of WebDriver APIs available in Selenium?

- Gecko Driver - Internet Explorer Driver - Chrome Driver - Safari Driver - HTMLUnit Driver - Opera Driver - Android Driver - iPhone Driver

When you use these locators ID, Name, XPath, Or CSS Selector?

- ID & Name locators will be used when there are unique identifiers & unique names available on the web page. - CSS Selector can be used for performance and when ID & Name locators are not unique. - XPath is used when there is no preferred locators.

What are the types of waits available in Selenium WebDriver?

- Implicit Waits: Implicit waits tell to the WebDriver to wait for a certain amount of time before it throws an exception driver.manage().timeouts().implicitlyWait(TimeOut, TimeUnit.SECONDS); --------------------------------------------------------- - Explicit Waits: The Explicit Wait in Selenium is used to tell the Web Driver to wait for certain conditions. Expected Conditions that can be used in Explicit Wait -> alertIsPresent() -> elementSelectionStateToBe() -> elementToBeClickable() -> elementToBeSelected() -> frameToBeAvaliableAndSwitchToIt() -> invisibilityOfTheElementLocated() -> invisibilityOfElementWithText() -> presenceOfAllElementsLocatedBy() -> presenceOfElementLocated() -> textToBePresentInElement() -> textToBePresentInElementLocated() -> textToBePresentInElementValue() -> titles() -> title Contains() -> visibility Of() -> visibilityOfAllElements() -> visibilityOfAllElementsLocatedBy() -> visibilityOfElementLocated() WebDriverWait wait = new WebDriverWait (driver, 10) wait.until(ExpectedConditions.titleIs("title name") ------------------------------------------------------------- Fluent Waits: FluentWait can define the maximum amount of time to wait for a specific condition and frequency with which to check the condition before throwing an "ElementNotVisibleException" exception.

What are the open-source Frameworks supported by Selenium WebDriver?

- JUnit - TestNG - Cucumber - JBehave

What are the challenges and limitations of Selenium WebDriver?

- Limited reporting - We cannot test windows application - We cannot test mobile apps - Handling dynamic Elements - Windows based pop-ups - Automating captcha is not possible

What are the different exceptions you have faced in Selenium WebDriver?

- NoSuchElementException - NoSuchWindowException - NoSuchFrameException - NoAlertPresentException - InvalidSelectorException - ElementNotVisibleException - ElementNotSelectableException - TimeoutException - NoSuchSessionException - StaleElementReferenceException

What is Page Object Model in Selenium?

- Page Object Model (POM) is a design pattern, popularly used in test automation that creates Object Repository for web UI elements. - The advantage of the model is that it reduces code duplication and improves test maintenance

What are the advantages of the Test Automation Framework?

- Reusability of code. - Easy reporting. - Low-cost maintenance. - Maximum Coverage - Minimal manual intervention - Save time and money

What are the benefits of Software Automation Testing?

- Saves time and money - Reusability of code - Easy reporting - Low-cost maintenance - Maximum coverage - Automated testing is more reliable

What is Selenium?

- Selenium is a suite of software tools to AUTOMATE WebBrowser. - Selenium is an open-source automated testing suite to test web applications. It supports different platforms and browsers.

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

- Single Slash "/" - Single slash is used to create XPath with ABSOLUTE path( i.e. the XPath would be created to start selection from the document node/start node. - Double Slash "//" - 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

What are Soft Assert and Hard Assert in Selenium?

- Soft Assert: Soft Assert collects errors during @Test Soft Assert DOES NOT throw an exception when an assert fails and would continue with the next step after the assert statement. ----------------------------------------------------------- - Hard Assert: Hard Assert throws an AssertException immediately when an assert statement fails and test suite continues with next @Test

How to submit a form using Selenium WebDriver?

- We use "submit" method on element to submit a form for example: driver.findElement(By.id("FORM")).submit(); note: We can use "click" method on the element which does form submission

Can we navigate back and forth in a browser in Selenium WebDriver?

- We use Navigate interface to do navigate back and forth in a browser. It has methods to move back, forward as well as to refresh a page. driver.navigate().forward(); driver.navigate().back(); driver.navigate().refresh(); driver.navigate().to("URL");

How to click on a hyperlink using Selenium WebDriver?

- We use click() method in Selenium to click on the hyperlink for example: driver.findElement(By.linkText("google website")).click();

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

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

What is the difference between driver.getWindowHandle() and driver.getWindowHandles() in Selenium WebDriver?

- driver.getWindowHandle() - It returns a handle of the current page (a unique identifier) -------------------------------------------------------------- - driver.getWindowHandles() - It returns a set of handles of the all the pages available.

What is the difference between driver.findElement() and driver.findElements() commands?

- findElement() returns A SINGLE WebElement (found first) based on the locator passed as parameter. - if NO element is found then findElement() throws NoSuchElementException - driver.findElement(By.id("value")); ----------------------------------------------------------- - findElements() returns a list of WebElements, all satisfying the locator value passed. - if NO element is found then findElements() returns a list of 0 elements. - List <WebElement> elements = element.findElements(By.id("value"));

What is the difference between driver.findElement() and driver.findElements() commands? What is the return type of findElements?

- findElement() will return ONLY SINGLE WebElement and if that element is NOT located or we use some wrong selector then it will throw NoSuchElementexception. - It find the first element within the current page using the locators -------------------------------------------------------------- - findElements() will return LIST of WebElements - It returns EMPTY LIST, when element is NOT found on current page as per the given element locator mechanism. It DOESN'T throws NoSuchElementException

How to deal with frame in WebDriver?

-> Using switch commands we can switch to different frame to handle elements; ------------------------------------------------------------- Select iframe by id driver.switchTo().frame("id of the frame); -------------------------------------------------------------- Switch to Frames by index driver.switchTo().frame(0); -------------------------------------------------------------- Locating iframe using tagName driver.switchTo().frame(driver.findElements(By.tagName("iframe").get(0);

How to get a text of a web element?

-By using getText() method driver.findElement(By.xpath("xpath value)).getText();

How to delete cookies in Selenium?

-We can use deleteAllCookies() method. driver.manage().deleteAllCookies();

How can we maximize browser window in Selenium?

-We can use maximize() method. driver.manage().window().maximize();

What is the alternative to driver.get() method to open an URL using Selenium WebDriver?

Alternative method to driver.get("URL") method is driver.navigate.to("URL")

What happen if you mix both implicit wait and explicit wait in a Selenium Script?

As per the official Selenium documentation, it is suggested not to mix both Implicit waits and Explicit Waits. Mixing both of them can cause unpredictable wait times.

What is Software Automation Testing?

Automation testing is the process of testing a software or application using an automation testing tool to find the defects. It is required when we have huge amount of regression test cases.

How to mouse hover on a web element using WebDriver?

By using Actions class --> WebElement element = driver.findElement(By.id("value")); **Creating object 'action' of an Actions class --> Actions act = new Actions(driver); **Mouseover on an element --> act.moveToElement(element).perform();

How to select a value in a dropdown?

By using Select class; WebElement selectElement = driver.findElement(By.name("dropdwn")); Select dropdwn = new Select(selectElement); ---> dropdwn.selectByVisibleText(Text); ---> dropdwn.selectByIndex(Index); ---> dropdwn.selectByValue(Value);

Write a code to read the text box value?

By using getAttribute() method we can get the value of the text box. String sText = driver.findElement(By.id("value)).getAttribute(); System.out.println(sText);

How do you verify if the checkbox or radio button is selected or not?

By using isSelected() method, we can identify whether it is selected or not. The return type is BOOLEAN. So if it returns "true" then button is selected else it is not selected.

How to switch between frames in Selenium?

By using the following code, we could switch between frames. --> driver.switchTo().frame();

What is the use of deselectAll() method?

It is used to deselected all the web elements which have been selected earlier. --> listbox.deselectAll();

How To Scroll Web Page Down Or UP Using Selenium WebDriver?

JavaScript scrollBy() method scrolls the document by the specified number of pixels. JavascriptExecutor js = (JavascriptExecutor) driver; js.executeScript("window.scrollBy(0,-250)", " ");

What is Page Factory?

Page Factory is an inbuilt Page Object Model concept for Selenium WebDriver but it is very optimized. Additionally, with the help of the PageFactory class, we will use annotations @FindBy to find WebElement.

When do you use Selenium Grid?

Selenium Grid can be used to execute same or different test scripts on multiple platforms and browsers concurrently so as to achieve distributed test execution

What are different selenium components?

Selenium IDE Selenium RC Selenium WebDriver Selenium Grid

How can we handle windows based pop up?

Selenium doesn't support windows based applications. - We could handle windows based popups in Selenium using some third party tools such as AutoIT, Robot class etc.

What are the testing types can be supported by Selenium?

Selenium supports the following types of testing - Functional Testing - Regression Testing - Retesting - Acceptance Testing - End-to-End Testing - Smoke Testing - Sanity Testing - Cross Browser Testing - UI Testing - Integration Testing

How to get the text of a web element?

String buttonText= driver.findElement(By.xpath("//*[@attribute='value']")).getText();

Selenium locators

There are 8 locators in Selenium. Id name ClassName TagName LinkText partial LinkText CSS selector Xpath

How to Upload a file in Selenium WebDriver?

There are two cases which are majorly used to upload a file in Selenium WebDriver such as using SendKeys Method and using AutoIT Script

Write a code to get title of the page ?

To get the title, we will use getTitle() method and here is the code; WebDriver driver = new ChromeDriver(); driver.get("http://www.google.com"); String strTitle=driver.getTitle(); System.out.println(strTitle);

How can we handle Web-based Pop-ups or Alerts in Selenium?

To handle Web-based alerts or popups, we need to do switch to the alert window and call Selenium WebDriver Alert API methods. --> dismiss(): To click on Cancel button. --> accept(): To Click on OK button. --> getText(): To get the text which is present on the Alert. --> sendKeys(): To enter the text into the alert box.

What is the difference between "type keys" and type commands?

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

How To Perform Right Click (Context Click) In Selenium WebDriver? Double Click? Hover over on a web element? Drag And Drop?

Using action class we can perform all of these operations Actions action = new Actions(driver); WebElement element=driver.findElement(By.linkText("test")); --> Double click <-- action.doubleClick(element).perform(); action.moveToElement(element).perform(); --> Right Click <-- action.contextClick(element).perform(); --> mouse over <-- WebElement element = driver.findElement(By.name("source")); WebElement target = driver.findElement(By.name("target")); action.dragAndDrop(element, target).perform();

How to handle hidden elements in Selenium WebDriver?

We can handle hidden elements by using javaScript executor (JavascriptExecutor(driver)).executeScript("document.getElementsByClassName("value").click();");

What are operations can you do using actions class?

We can perform following operation using action class: -> click (): Simply click on element -> doubleClick (): Double clicks on Element -> contextClick() : Performs a context-click (right click) on an element -> clickAndHold(): Clicks at the present mouse location (without releasing) -> dragAndDrop(source, target): Invokes click-and-hold at the source location and moves to the location of the target element before releasing the mouse. source - element to grab, target - element to release

How to capture Screenshot in Selenium WebDriver?

We use TakeScreenShot interface to capture screenshot ------------------------------------------------------------- 1. Convert web driver object to TakeScreenshot TakesScreenshot scrShot((TakesScreenshot)webdriver); -------------------------------------------------------------- 2. Call getScreenshotAs method to create image file File SourceFile=scrShot.getScreenshotAs(OutputType.FILE); ------------------------------------------------------------- 3. Move image file to new destination --> File DestinationFile=new File(fileWithPath); -------------------------------------------------------------- 4. Copy file at destination --> FileUtils.copyFile(SourceFile, DestinationFile);

How to find whether an element is displayed on the web page?

WebDriver facilitates the user with the following methods to check the visibility of the web elements. These web elements can be buttons, drop boxes, checkboxes, radio buttons, labels etc. - isDisplayed() driver.findElement(By.xpath("xpath")).isDisplayed(); - isSelected() driver.findElement(By.xpath("xpath")).isSelected(); - isEnabled() driver.findElement(By.xpath("xpath")).isEnabled();

How to launch a browser using Selenium WebDriver?

WebDriver is an Interface. We create an Object of a required driver class such as FirefoxDriver, ChromeDriver, InternetExplorerDriver etc., - To launch Chrome Driver: WebDriver driver = new ChromeDriver();

What is WebElement selenium?

WebElement in Selenium represents an HTML element. It basically represents a DOM element in a HTML document.

What is an XPath?

XPath is used to locate the elements. Using XPath, we could navigate through elements and attributes in an XML document to locate web elements.

What is the use of getOptions() method?

getOptions() is used to get the selected options from drop the dropdown list.

How to fetch the current page URL in Selenium?

we can use getCurrentURL() driver.getCurrentUrl();


Ensembles d'études connexes

Tissue integrity/infection/vaccines

View Set

Chapter 25: Care of Patients with Skin Problems

View Set

USII.5a Imperialism and the Spanish-American War

View Set

Arkansas and the Southwest FINAL

View Set

3. Regulation of Acid-Base Balance

View Set

Introductory Microeconomics Chp. 1 Quiz

View Set

Joint categories and synovial joints structure

View Set

APUSH ch. 13-15 New National Economy and Culture

View Set