Selenium IQ

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

What is WebDriverWait In Selenium WebDriver?

-- WebDriverWait is actually a type or a specific implementation of Explicit Wait in Selenium WebDriver that provides various methods to wait for a certain condition with a specified maximum time limit. -- WebDriverWait wait=new WebDriverWait(drv,30); wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("ckdmc"));

Explain the line of code public static WebDriver driver = new ChromeDriver();

// instantiate an instance of ChromeDriver, which will be driving our browser.

Explain the line of code driver.get("http://google.com");

// navigate to the specific url.

Explain the line of code: System.setProperty("webdriver.chrome.driver", driverPath+"chromedriver.exe");

// set the property for chrome driver, specify its location via the webdriver.chrome.driver.

Write a dynamic XPath to locate a table's 2nd row 3rd column data.

//to get 2nd row 3rd column data WebElement cellIneed = tableRow.findElement(By.xpath("//table/tbody/tr[2]/td[3]"));

Have you encountered StaleElementReferenceException ever and how you handled it?

1. We could refresh the page and try again for the same element. 2. Wait for the element till it gets available wait.until(ExpectedConditions.presenceOfElementLocated(By.id("table")));

What is a headless browser?

A headless browser is a browser without a GUI (Graphical User Interface) used for web automation and other tasks, such as testing and web scraping. Examples include Google Chrome Headless, Mozilla Firefox Headless, and PhantomJS.

How To Perform Double Click Action In Selenium WebDriver?

Actions action = new Actions(driver); WebElement element=driver.findElement(By.linkText("TEST")); action.doubleClick(element).perform();

1) What is Implicit/Explicit/ Fluent Wait In Selenium WebDriver?

All three techniques handle synchronization issues when testing web applications. · Implicit wait sets a default wait time for the WebDriver instance. · Explicit wait waits for a specific condition to occur for a set time. · Fluent wait waits for a certain condition to occur at regular intervals.

Which one is better? Xpath or CSS

Both CSS and XPATH are great in Selenium Automation. When we want to automate the test Case on Internet Explorer sometimes CSS Selector is better and for the rest (Browser i.e. Firefox, Chrome and Safari) Xpath is better

How to Download a file in Selenium WebDriver?

By using AutoIT script, we could download a file in Selenium WebDriver. To upload or download files in Selenium we can use Robot Class or get help from AutoIT or Sikuli. AutoIt is just another automation tool like Selenium but unlike Selenium it is used for Desktop Automation rather Web Automation. Robot Class is a Java based class that can simulate keyboard events in Selenium.

How to select a value in a dropdown?

By using Select class Select dropdown = new Select(driver.findElement(By.id("designation"))); ● dropdown.selectByVisibleText("Value"); ● dropdown.selectByIndex(1); ● dropdown.selectByValue("value");

Which WebDriver implementation claims to be the fastest?

HTMLUnitDriver, because it is headless browser which have less User Interface

Scenario: you have 2 frames on the page and in 1 you need to enter some text in second you need to click a button. How can you do that?

I will first switch frame 1 driver.switchTo().frame(1); and enter text then come to default main using driver.switchTo().defaultContent(); again I will switch to second frame driver.switchTo().frame(2); and click on button

What are the types of waits available in Selenium WebDriver?

Implicit Wait, Explicit Wait, Fluent Wait

What is the return type of findElements?

It returns a List.

How to input text in the text box without calling the sendKeys()?

JavascriptExecutor executor = (JavascriptExecutor)driver; executor.executeScript ("document.getElementById("email") .value='[email protected] re');

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

Navigate to. driver.navigate().to("http://www.example.com") ;

Is it possible to automate the captcha using Selenium?

No we can't automate captcha.

Can you switch from frame to frame directly?

No, frames are nested in Selenium WebDriver, so you need to navigate through each frame using switchTo() after switching to the default content.

What is Page Object Model? (POM)

POM is a Selenium pattern to separate web elements and test scripts for better code organization and maintainability.

What is the difference between POM and PageFactory?

POM is a pattern that separates web elements and test scripts into different classes. PageFactory is an implementation of the POM pattern that uses annotations to initialize web elements in a single class. Example from our framework: @FindBy (name= "txtPassword" ) public WebElement password ; public LoginPageElements() { PageFactory. initElements (BaseClass. driver , this ); }

What is Selenium Grid?

Selenium Grid is a tool used to distribute your test execution on multiple platforms and environments concurrently.

What is Selenium IDE?

Selenium IDE Selenium IDE (Integrated Development Environment) is a Firefox plugin.

What is Selenium RC?

Selenium RC AlsoKnownAs Selenium Remote control / Selenium 1.

What is Selenium WebDriver?

Selenium WebDriver AKA Selenium 2 is a browser automation framework that accepts commands and sends them to a browser. It is implemented through a browser-specific driver. It controls the browser by directly communicating with it.

List some scenarios which we cannot automate using Selenium WebDriver?

Selenium WebDriver cannot automate scenarios involving captcha or reCaptcha tests, video or audio playback testing, mobile or desktop applications testing, applications behind a firewall, and third-party plugins such as Adobe Flash or Java applets.

What are the common test automation tools?

Selenium and QTP - (Quick Test Professional)

What are the testing types that can be supported by Selenium?

Selenium can support various types of testing such as · Functional testing: testing the application functions as expected. · Regression testing: ensuring changes don't break existing functionality. · Integration testing: verifying interactions between different components of the application. · Performance testing: measuring the application's performance under various load conditions. · Acceptance testing: verifying the application meets user requirements. · Cross-browser testing: ensuring the application works on different web browsers.

What is selenium?

Selenium is a suite/group/collection of software tools to automate Web Browsers.

What is StaleElementReferenceException?

StaleElementReferenceException - One of the worst exceptions for an automation engineer. StaleElementReferenceException occurs in Selenium when an element is no longer valid or attached to the current DOM (Document Object Model)/ web page for example the element is removed or modified by the time you try to interact with it.

Is there a way to click hidden LINK in WebDriver?

Store that element in object, then click on that hidden element. WebElement element="property of element"; JavascriptExecutor js = (JavascriptExecutor)driver; js.executeScript ("arguments[0].click();",element);

How to get a text of a web element?

String buttonText = driver.findElement(By.cssSelector("div.success")). getText();

How to get an attribute value using Selenium WebDriver?

String innerText = driver.findElement(By.cssSelector("div.success")). getAttribute("type");

What is the super interface of WebDriver?

The Super interface of WebDriver is SearchContext Interface.

What is the difference between Absolute Path and Relative Path?

The main difference between absolute path and relative path is that an absolute path specifies the full path of a file or directory starting from the root directory, while a relative path specifies the path relative to the current working directory. In other words, an absolute path provides the complete path to an element in the file system, while a relative path provides the path from the current location to the element.

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

The navigate interface also exposes the ability to move backwards and forwards in our browser's history: driver.navigate().forward(); driver.navigate().back();

What are the Locators available in Selenium?

There are eight locators in selenium to identify the webelements on the webpage : ID, ClassName, Name, TagName, LinkText, PartialLinkText, XPath, CSS Selector. · ID: Locates elements with a specific ID attribute. · Name: Locates elements with a specific name attribute. · Class Name: Locates elements with a specific CSS class attribute. · Tag Name: Locates elements with a specific HTML tag. · Link Text: Locates anchor elements with a specific link text. · Partial Link Text: Locates anchor elements with a partial link text. · CSS Selector: Locates elements using a CSS selector. · XPath: Locates elements using an XPath expression.

How many ways can you handle alerts?

There are four methods that we could use to handle Alerts. Alert alert = driver.switchTo().alert(); or driver.switchTo().alert() · void dismiss() - The dismiss() method clicks on the "Cancel" button as soon as the pop up window appears. alert.dismiss(); or driver.switchTo().alert().dismiss(); · void accept() - The accept() method clicks on the "Ok" button as soon as the pop up window appears. alert.accept(); or driver.switchTo().alert().accept(); · String getText() - The getText() method returns the text displayed on the alert box. alert.getText(); or driver.switchTo().alert().getText(); · void sendKeys(String stringToSend) - The sendKeys() method enters the specified string pattern into the alert box. alert.sendkeys("text"); or driver.switchTo().alert().sendkeys("text");

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. sendKeys() method on the file-select input field to enter the path to the file to be uploaded ... WebElement uploadElement = driver.findElement(By.id("uploadfile_0")); // enter the file path onto the file-selection input field uploadElement.sendKeys("C:\\newhtml.html");sendKeys() method on the file-select input field to enter the path to the file to be uploaded ... WebElement uploadElement = driver.findElement(By.id("uploadfile_0")); // enter the file path onto the file-selection input field uploadElement.sendKeys("C:\\newhtml.html");

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

Thred.sleep(5000);

How can you handle JavaScript Alerts?

To handle JavaScript alerts, use the Alert interface provided by the browser. You can use methods like getText() to get the message and accept() to click the OK button.

How do you work with radio buttons which do not have an id attribute?

To work with radio buttons without an ID, locate them using other locators and use the click() method to select them. Alternatively, use the isSelected() method to check if the button is already selected before selecting it. List<WebElement> radioBtn=driver.findElements(By.name("sex")); for(WebElement radio: radioBtn) { String value=radio.getAttribute("value"); if(radio.isEnabled() && value.equals("Female")) { radio.click(); break; }}

How to check the multiple selected value in a dropdown?

Use the isMultiple() method on the Select object for the dropdown to check if it allows multiple selections. If it returns true, the dropdown allows multiple selections. Select listbox = new Select(driver.findElement(By.xpath("//select[@id='FromLB']"))); if (blistbox.isMultiple()){ listbox.selectByVisibleText("Value"); listbox.selectByVisibleText("Value"); }

Let's say I have a page and on that page there is a web table that has 4 columns and twenty rows. And I have to validate data in the last rows?

Use xpath index concept and take text of last row and do assertion driver.get(url); List<WebElement> rows = driver.findElements(By.xpath( "//table[@summary='Sample Table']/tbody/tr" )); for ( int i = rows .size()-1; i>=0; i--) { String lastRowValue = rows .get( i ).getText(); System. out .println( lastRowValue ); break ; }

How do you handle an element in different windows?

Using Switch To methods allowing us to switch control from one window to another. When multiple tabs open, Selenium focuses on the first window by default.

Drag and Drop Method

Using action class Actions action = new Actions(driver); WebElement element = driver.findElement(By.name("source")); WebElement target = driver.findElement(By.name("target")); action.dragAndDrop(element, target).perform();

Hover over on a web element?

Using action class Actions action = new Actions(driver); WebElement element=driver.findElement(By.linkText("TEST")); action.moveToElement(element).perform();

How can we handle web based pop-up?

We can handle web based pop-ups using Alert Interface.

Scenario: there is a submit button on the page it has id property. By using id we got an element not found exception, how will you handle this situation?

We can try alternative locators, double-check the ID, wait for the element to load, check if it is within a frame, or ensure it is visible and enabled.

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

We use JavascriptExecutor //to perform Scroll Up on application using Selenium JavascriptExecutor js = (JavascriptExecutor) driver; js.executeScript("window.scrollBy(0,250)"); //to perform Scroll Down on application using Selenium JavascriptExecutor js = (JavascriptExecutor) driver; js.executeScript("window.scrollBy(0, -400)"); //to scroll an application to specified elements JavascriptExecutor je = (JavascriptExecutor) driver; je.executeScript("arguments[0].scrollIntoView(true);",element);

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.

In which situations are you going to use Xpath?

XPath is used when other locators are not available or not sufficient, and it allows for more complex and flexible selection of web elements. It is particularly useful for testing web applications with complex or dynamic user interfaces.

Have you done any cross browser testing within your Project?

Yes I have done cross browser testing in my framework using 3 browser initialization. Chrome , IE and Firefox testing using Webdriver. In our property file we store keys for the browser and everytime we change the value of the key execution will be happening on different browsers.

Can we inspect an alert?

Yes, you can inspect an alert using the browser developer tools.

Which locator do you prefer?

You can mention that preference of the locator depends on the project CSS selector because it is fast, efficient, and flexible in selecting web elements based on various attributes. It also supports advanced selection strategies and is widely used in web development.

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

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

How to press the RETURN key in Selenium?

driver.findElement(By.id("Value")) .sendKeys(Keys.RETURN);

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

findElement() will return only a single WebElement and if that element is not located or we use some wrong selector then it will throw NoSuchElementexception. findElements() will return List of WebElements - It returns an empty list, when element is not found on the current page as per the given element locator mechanism. It doesn't throws NoSuchElementException

Write a method to switch to the window based on title?

public switchToWindow(String titleName) { driver.switchTo().window("titleName"); //titleName =windowName }

How do you send text to alert?

void sendKeys(String stringToSend) // The sendKeys() method enters the specifiedstring pattern into the alert box. alert.sendkeys("text"); or driver.switchTo().alert().sendkeys("text");

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

we can input text using sendkeys WebElement email = driver.findElement(By.id("email")); email.sendKeys("[email protected]");

Write a complex xpath or css expression?

xpath: "//label[@for='personal_txtLicExpDate']/following-sibling::img" css: "input[name^='pass']"

Getwindowhandle vs Getwindowhandles and the return types.

· Use getWindowHandle() to get the current page's handle, a unique identifier for the webpage. String handle= driver.getWindowHandle(); · Use getWindowHandles() to get all open window handles. Switch between windows with Set<String> handle= driver.getWindowHandles(); //Return a set of window handles · SwitchTo().Window("handle") to switch to the window you desire. · SwitchTo().Window("mywindowID") if you know the window ID. · Use SwitchTo().Window("") to return to the main window.

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

● JUnit ● TestNG ● Cucumber ● JBehave

What are the types of WebDriver APIs available in Selenium?

● Gecko Driver ● InternetExplorer Driver ● Chrome Driver ● Safari Driver ● HTMLUnit Driver

What are the advantages of Selenium Grid?

● It allows running test cases in parallel thereby saving test execution time. ● It allows multi-browser testing ● It allows us to execute test cases on multi-platform

Why do you prefer the Selenium Automation Tool?

● It is an Open source suite of tools mainly used for Functional and Regression Test Automation. ● Selenium supports various Operating environments such as MS Windows,Linux,Macintosh etc... ● Selenium supports various Browsers such as Mozilla Firefox,IE,Google Chrome,Safari,Opera etc... ● Selenium supports various programming environments to write programs (Test scripts): Java,C#,Python,Perl,Ruby,PHP, JS

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 and It is called Absolute XPath. Example : /html/body/td/tr/div[1]/div[2] ● 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. And it is called Relative XPath. Example : //input[@id='username']

What operations can you do using Actions class?

● click (): Simply click on element ● doubleClick (): Double clicks on Element ● contextClick() : Perform a context-click (right click) on an element ● cli ckAndHold(): 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 do you get text from alert?

Alert alert = driver.switchTo().alert(); or driver.switchTo().alert() String getText() // The getText() method returns the text displayed on the alert box. alert.getText(); or driver.switchTo().alert().getText();

What are the advantages of Page Object Model?

Code reusability: write code once and reuse it in multiple tests Code maintainability: separation of test and page-specific code makes it easy to maintain and update code. Object repository: defining pages as Java classes makes it easy to manage elements and actions and reuse code. Readability: separation of code makes the code more readable.

When do you use Selenium Grid?

Selenium Grid is used to run tests in parallel on multiple machines or browsers, for example, when testing a website on different operating systems and browsers simultaneously, or when running tests on different versions of an application. It is also used to distribute tests across multiple teams or locations and increase test reliability.

How can we handle windows based pop up?

Selenium WebDriver cannot handle window based pop ups, for that we can use Robot Class or third-party tools like AutoIT.

What is the difference between XPATH and CSS?

Speed wise CSS and XPATH can be equal, or either one would be a bit speedier than the other.Therefore speed comparison can be ignored. However, off the record, I have encountered that CSS is much faster than XPATH in IE Browser. ● Generally CSS is easy to use and readable over XPATH. ● CSS works only in forward direction while with xpath, we can search elements backward or forward ● Xpath can work with text while CSS cannot

How do you handle WebTables?

Step 1- Click on calendar Step 2- Get all td of tables using findElements method Step 3- using for loop get text of all elements Step 4- using if else condition we will check specific date Step 5- If the date is matched then click and break the loop. List<WebElement> row =driver.findElements(By.xpath("//table[@id='resultTable']/tbody/tr")); for (int i = 1; i <=rows.size(); i++) { String rowData = rows.get(i).getText(); if (rowData.contains(ID)) { driver.findElement(By.xpath ("//table[@id='resultTable']/ tbody/tr["+i+"]/td[1]/input")).click(); break; }}

How do you handle the calendar elements?

Step 1- Click on calendar Step 2- Get all td of tables using findElements method Step 3- using for loop get text of all elements Step 4- using if else condition we will check specific date Step 5- If the date is matched then click and break the loop. driver.findElement(By.id("datepicker")).click(); List<WebElement> allDates=driver.findElements (By.xpath("//table[@class='ui-datepicker-calendar']/tbody/tr/td")); for(WebElement ele:allDates) { String date=ele.getText(); if (date.equalsIgnoreCase("28")) { ele.click(); break; }}

How to handle hidden elements in Selenium WebDriver?

Store that element in an object.

How to launch a browser using Selenium WebDriver?

System.setProperty("webdriver.chrome.driver", driverPath+"chromedriver.exe"); public static WebDriver driver = new ChromeDriver(); driver.get(" http://google.com" ) ;

Suppose the developer changed the existing image to a new image with the same xpath. Does the test case pass or fail?

Test case will pass because we can not check the image using selenium.

How to identify the frame which does not have Id as well as name?

This can be done using a loop and conditional statements to check the content of each frame. // Loop through all frames for (var i = 0; i < window.frames.length; i++) { // Check if the frame contains a specific element if (window.frames[i].document.getElementById('myElement')) { console.log("Frame found with element:", window.frames[i]); break; // Stop looping once the frame is found }}

How To Login Into Any Site If It Is Showing Any Authentication Pop-Up for a Username And Password?

To do this we pass username and password with the URL http://username:password@url e.g. http://myUserName:[email protected] Testing URL: http://abcdatabase.com/basicauth Code: driver.get(" http://test:[email protected]/basicauth ");

How can you find Broken Links/Images in a page using Selenium WebDriver?

To find broken links/images using Selenium WebDriver: get all links/images, extract their URLs, send an HTTP request to each URL, and check the status code. ● Collect all the links from the webpage. All the links are associated with the Tag 'a'. ● Create a list of type WebElement to store all the Link elements in it. ● Now Create a Connection using URL object( i.e ., link) ● Connect using the Connect Method. ● Use getResponseCode () to get response code. eg 200 Some of the HTTP status codes: 200 - Valid Link 404 - Link not found 400 - Bad request 401 - Unauthorized 500 - Internal Error While doing validation you only have to verify status 200- Success- ok List<WebElement> links = driver.findElements(By.tagName("a")); for (int i=0; i<links.size(); i++) { String linkURL = links.get(i).getAttribute("href"); if (linkURL!= null) { URL obj = new URL(linkURL); HttpURLConnection conn = ((HttpURLConnection) obj.openConnection()); int rCode = conn.getResponseCode(); if (rCode == 200) { System.out.println(i+ " Link is valid------" + linkURL); } else { System.out.println(i+ " Link is broken------" + linkURL);} }else { System.out.println(links.get(i).getText()); System.out.println(i+ " Link is broken ********" + linkURL); }}

How To Perform Right Click in Selenium WebDriver?

Using action class Actions action = new Actions(driver); WebElement element= driver.findElement(By.linkText("TEST")); action.contextClick(element).perform();

How would you handle elements that are in a different frame?

Using switch commands we can switch to different frame to handle elements. · Switch to Frame by Name or ID o driver.switchTo().frame("iframe1") · Switch to Frame by WebElement o WebElement iframeElement = driver.findElement(By.id("IF1")); driver.switchTo().frame(iframeElement); · Switch to Frames by Index o driver.switchTo().frame(0)

Which version of Selenium Webdriver are you using?

We are using the Selenium 3.0 because of compatibility issues which can support most of the latest browsers any way we are creating maven project any dependency we can easily update in pom.xml file

How to capture Screenshot in Selenium WebDriver?

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

How to press the TAB key in Selenium?

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

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

· close() - It is used to close the browser or page currently which is having the focus. · quit() - It is used to shut down the webdriver instance or destroy the web driver instance (Close all the windows).

Scenario: there is a submit button on the page it has id property. By using id we got an element not found exception, What might be the problem in this case?

· incorrect ID · unloaded element · iframe containment · hidden/disabled element · or typos/removal

Challenges, issues and limitations of Selenium?

● Automating Captcha (Completely Automated Public Turing test to tell Computers and Humans Apart) is not possible, differentiate between Computer and Human. ● We can not read barcode using Selenium WebDriver ● Windows based pop ups ● Image validation and comparison ● PDF validation and comparison

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

● ElementNotVisibleException ● NoSuchElementException ● NoSuchFrameException ● NoAlertPresentException ● NoSuchWindowException ● StaleElementReferenceException


Kaugnay na mga set ng pag-aaral

Excel- Chapter 11: Securing Workbooks

View Set

CCNA 1 v7 Modules 16 - 17: Building and Securing a Small Network

View Set

Insurance Quizzes, P&C Insurance Basics (ExamFX), ExamFX P&C Licensing, examfx insurance, Property and Casualty- Examfx, GENERAL INSURANCE EXAMFX, Exam FX P&C Questions, Exam FX P&C, Dwelling Policy (examfx falshcards), P&C examfx, GENERAL INSURANCE...

View Set

MGT 3200 CH. 5 - Strategic Planning

View Set

Unit 7 - WWII - Mobilization of America

View Set

Northern Europe & the Low Countries

View Set