Selenium Java Interview Questions: Selenium is a popular open-source automation testing tool widely used for web application testing. With the growing demand for automation testing, the usage of Selenium has also increased rapidly. As a result, companies are now looking for professionals who have expertise in Selenium with Java programming.
Therefore, it has become crucial for aspiring automation testers to prepare themselves for Selenium Java interview questions. In this context, this article will cover some of the commonly asked Selenium Java interview questions, which will help candidates to understand the concepts, enhance their knowledge, and prepare themselves for the interview.
Selenium Java Interview Questions
What is Selenium, and what is composed of?
Ans: Selenium is a suite of tools for automated web testing. It is composed of
- Selenium IDE (Integrated Development Environment): It is a recording and playing-back tool. It is a Firefox plugin
- WebDriver and RC: It provides the APIs for various languages like Java,.NET, PHP, etc. With most browsers Webdriver and RC work.
- Grid: With the help of Grid, you can distribute tests on multiple machines so that tests can be run parallel, which helps cut down the time required for running in-browser test suites.
What is Selenium 2.0?
Ans: Web testing tools Selenium RC and WebDriver are consolidated in a single tool in Selenium 2.0
Mention what is Selenium 3.0?
Ans: Selenium 3.0 is the latest version of Selenium. It has released 2 beta versions of selenium 3.0 with a few of the below changes: Here are a few new features added to Selenium 3.0
- Beta 1 updates Beta 2 updates (Only for Java)
- The minimum Java version is now 8+
- System property webdriver.firefox.marionette now forces the server in marionette or legacy firefox driver mode, ignoring any related Desired Capability
- It will support Firefox Via Mozilla’s gecko driver.
- Grid fixes NPEs on registration when -the browser is not specified
- MS provides support for Edge.
- It now supports Safari on macOS via Apple’s own Safari driver
- Update GeckoDriver –port argument in all bindings
How will you find an element using Selenium?
Ans: In Selenium, every object or control in a web page is referred to as an element; there are different ways to find an element on a web page; they are:
- ID
- Name
- Tag
- Attribute
- CSS
- Link text
- PartialLink Text
- Xpath etc
List out the test types that Selenium supports.
Ans: For web-based application testing selenium can be used. The test types that can be supported are
- Functional
- Regression
For post-release validation, a continuous integration automation tool could be used.
- Jenkins
- Hudson
- Quick Build
- CruiseCont
Explain what an assertion is in Selenium and the types of assertions.
Ans: Assertion is used as a verification point. It verifies that the state of the application conforms to what is expected. The types of assertion are “assert”, “verify” and “waifFor”.
Mention what the use of X-path is.
Ans: X-Path is used to find the WebElement in web pages. It is also useful in identifying dynamic elements.
Explain the difference between single and double slash in X-path. Single slash ‘/.’
Ans:
- Single slash ( / ): start selection from the document node. It allows you to create ‘absolute’ path expressions.
- Double Slash ‘// ’: Double slash ( // ) start selection matching anywhere in the document. It enables to create of ‘relative’ path expressions.
List out the technical challenges with Selenium.
Ans: Technical challenges with Selenium are Selenium supports only web-based applications. It does not support the Bitmap comparison. Any reporting and related capabilities have to depend on third-party tools No vendor support for the tool compared to commercial tools like HP UFT. As there is no object repository concept in Selenium, the maintainability of objects becomes difficult.
What is the difference between type keys and type commands?
Ans: TypeKeys() usually triggers JavaScript events, whereas .type() won’t. The type key populates the value attribute using JavaScript, whereas .typekeys() emulates user typing.
What is the difference between verifying and assert commands?
Ans:
- Assert: Assert allows checking whether an element is on the page. The test will stop on the step fails if the asserted element is unavailable. In other words, the test will be terminated when the check fails.
- Verify: Verify command will check whether the element is on the page; if not, then the test will execute. In verification, all the commands will run guaranteed even if any tests fail.
What are JUnit Annotations, and what are the different types of annotations which are useful?
Ans: In JAVA, a special form of syntactic meta-data can be added to Java source code, known as Annotations. Variables, parameters, packages, methods, and classes are annotated. Some of the JUnit annotations which can be useful are
- Test
- Before
- After
- Ignore
- BeforeClass
- AfterClass
- RunWith
While using the click command, can you use screen coordinate?
Ans: To click on a specific part of an element, you would need to use the clickAT command. ClickAt command accepts element locator and x, y coordinates as arguments- clickAt (locator, cordString)
What are the advantages of Selenium?
Ans:
- It supports C#, PHP, Java, Perl, Python
- It supports different OS like Windows, Linux, and Mac OS.
- It has got powerful methods to locate elements (XPath, DOM, CSS)
- It has a huge developer community supported by Google
Why should testers opt for Selenium and not QTP?
Ans: Selenium is more popular than QTP as
- Selenium is open-source, whereas QTP is a commercial tool.
- Selenium is used especially for testing web-based applications, while QTP can also be used for client-server testing applications.
- Selenium supports Firefox, IE, Opera, and Safari operating systems like Windows, Mac, Linux, etc. however, QTP is limited to Internet Explorer on Windows.
- Selenium supports many programming languages like Ruby, Perl, and Python, whereas QTP supports only VB script.
What are the four parameters you have to pass in Selenium?
Ans: Four parameters that you have to pass in Selenium are
- Host
- Port Number
- Browser
- URL
What is the difference between the setSpeed() and sleep() methods?
Ans: Both will delay the speed of execution.
- Thread.sleep (): It will stop the current (java) thread for the specified time. It’s done only once
It takes a single argument in integer format.
Ex: thread.sleep(2000)- It will wait for 2 seconds. It waits only once at the command given at sleep. - SetSpeed (): For a specific amount of time, it will stop the execution for every selenium command.
It takes a single argument in integer format.
Ex: selenium.setSpeed(“2000”)- It will wait 2 seconds. Runs each command after setSpeed delay by the number of milliseconds mentioned in set Speed. This command is useful for demonstration purposes or using a slow web application.
What is the same-origin policy? How can you avoid the same-origin policy?
Ans: The “Same Origin Policy” is introduced for security reason, and it ensures that the content of your site will never be accessible by a script from another site. As per the policy, any code loaded into the browser can only operate within that website’s domain.
To avoid “Same Origin Policy” proxy injection method is used, in proxy injection mode the Selenium Server acts as a client configured HTTP proxy, which sits between the browser and application under test and then masks the AUT under a fictional URL
What are heightened privileges browsers?
Ans: The purpose of heightened privileges is similar to Proxy Injection, allows websites to do something that is not commonly permitted. The key difference is that the browsers are launched in a special mode called heightened privileges. By using this browser mode, Selenium core can open the AUT directly and also read/write its content without passing the whole AUT through the Selenium RC server.
How can you use “submit” a form using Selenium?
Ans: You can use “submit” method on an element to submit the form-
element.submit () ;
Alternatively, you can use the click method on the element which does form submissio
What are the features of TestNG and list some of the functionality in TestNG, which makes it more effective?
Ans: TestNG is a testing framework based on JUnit and NUnit to simplify a broad range of testing needs, from unit testing to integration testing. And the functionality which makes it an efficient testing framework is
- Support for annotations
- Support for data-driven testing
- Flexible test configuration
- Ability to re-execute failed test cases
Mention what the difference between Implicit wait and Explicit wait is?
Ans: Implicit Wait: Sets a timeout for all successive Web Element searches. For the specified amount of time, it will try looking for element again and again before throwing a NoSuchElementException. It waits for elements to show up.
Explicit Wait: It is a one-timer, used for a particular search.
Which attribute you should consider throughout the script in a frame for “if no frame Id as well as no frame name”?
Ans: You can use…..driver.findElements(By.xpath(“//iframe”))….
This will return a list of frames.
You will need to switch to each and every frame and search for locator which we want. Then break the loop
Explain what is the difference between findelements() and find element()?
Ans:
- findelement(): It finds the first element within the current page using the given “locating mechanism”. It returns a single WebElement
- findElements (): Using the given “locating mechanism” find all the elements on the current page. It returns a list of web elements.
Explain what the JUnit’s annotation linked with Selenium are?
Ans: The JUnits annotation linked with Selenium is
- @Before public void method() – It will perform the method () before each test, and this method can prepare the test
- @Test public void method() – Annotations @Test identifies that this method is a test method environment
- @After public void method()- To execute a method before this annotation is used, the test method must start with test@Before
Explain what Data-driven framework and Keyword driven is?
Ans:
- Data-driven framework: In this framework, the test data is separated and kept outside the Test Scripts, while test case logic resides in Test Scripts. Test data is read from the external files ( Excel Files) and are loaded into the variables inside the Test Script. Variables are used for both input values and verification values.
- Keyword-driven framework: The keyword-driven frameworks requires the development of data tables and keywords, independent of the test automation. In a keyword-driven test, the functionality of the application under test is documented in a table as well as step by step instructions for each test.
Explain how you can log in to any site if it’s showing any authentication popup for password and username?
Ans: Pass the username and password with URL
Syntax-HTTP://username:password@url
ex- http://creyate:tom@www.gmail.com
Explain how to assert text webpage using selenium 2.0?
Ans: WebElement el = driver.findElement(By.id(“ElementID”))
//get test from element and stored in text variable
String text = el.getText();
//assert text from expected
Assert.assertEquals(“Element Text”, text);
What is Object Repository?
Ans: object repository is an essential entity in any UI automation which allows a tester to store all object that will be used in the scripts in one or more centralised locations rather than scattered all over the test scripts.
Explain how Selenium Grid works?
Ans: Selenium Grid sent the tests to the hub. These tests are redirected to Selenium Webdriver, which launch the browser and run the test. With the entire test suite, it allows for running tests in parallel.
Can we use Selenium grid for performance testing?
Ans: Yes. But not as effective as a dedicated performance testing tool like LoadRunner.
List the advantages of Webdriver over Selenium Server?
Ans:
- If you are using Selenium-WebDriver, you don’t need the Selenium Server as it is using different technology
- Selenium Server provides Selenium RC functionality which is used for Selenium 1.0 backward compatibility
- Selenium Web driver makes direct calls to the browser using each browsers native support for automation, while Selenium RC requires selenium server to inject Javascript into the browser
Mention what the capabilities of Selenium WebDriver or Selenium 2.0 are?
Ans: WebDriver should be used when requiring improvement support for
- Handling multiple frames, pop-ups, multiple browser windows, and alerts
- Page navigation and drag & drop
- Ajax based UI elements
- Multi-browser testing including improved functionality for browser not well supported by Selenium 1.0
While injecting capabilities in webdriver to perform tests on a browser which is not supported by a webdriver, what is the limitation that one can come across?
Ans: The major limitation of injecting capabilities is that “findElement” command may not work as expected.
Explain how you can find broken images on a page using Selenium Web driver?
Ans:
- To find the broken images in a page using Selenium web driver is Get XPath and get all the links in the page using tag name In the page click on each and every link
- Look for 404/500 in the target page title
Explain how you can handle colours in web driver?
Ans: To handle colours in web driver you can use Use getcssvalue(arg0) function to get the colours by sending ‘color’ string as an argument
Using the web driver how you can store a value which is a text box?
Ans: You can use the following command to store a value which is text box using web driver
driver.findElement(By.id(“your Textbox”)).sendKeys(“your keyword”);
Explain how you can switch between frames?
Ans: To switch between frames webdrivers [ driver.switchTo().frame() ] method takes one of the three possible arguments
- A number: It selects the number by its (zero-based) index
- A number or ID: Select a frame by its name or ID
- Previously found WebElement: Using its previously located WebElement select a frame
Mention 5 different exceptions you had in Selenium web driver?
Ans: The 5 different exceptions you had in Selenium web drivers are
- WebDriverException
- NoAlertPresentException
- NoSuchWindowException
- NoSuchElementException
- TimeoutException
Explain using Webdriver how you can perform double click?
Ans: You can perform double click by using
Syntax- Actions act = new Actions (driver);
act.doubleClick(webelement);
How will you use Selenium to upload a file?
Ans: You can use “type” command to type in a file input box or upload file. Then, you have to use a “Robot” class in JAVA to make file upload work.
Which web driver implementation is the fastest?
Ans: HTMLUnit Driver implementation is fastest, HTMLUnitDriver does not execute tests on the browser but plain HTTP request, which is far quicker than launching a browser and executing tests
Explain how you can handle frames using Selenium 2.0?
Ans: To bring control on HTML frame you can use “SwitchTo” frame method-
driver.switchTo().frame(“frameName”);
To specify a frame you can use index number
driver.switchTo().frame(“parentFrame.4. frameName”);
This would bring control on frame named- “frameName” of the 4th subframe names “parentFrame”
What is the difference between getWindowhandles() and getwindowhandle()?
Ans:
- getwindowhandles(): It is used to get the address of all the open browser, and its return type is iterator<String>
- getwindowhandle(): It is used to get the address of the current browser where the control is, and return type is a string
Explain how you can switch back from a frame?
Ans: To switch back from a frame use method defaultContent()
Syntax-driver.switchTo().defaultContent();
List out different types of locators?
Ans: Different types of locators are
- By.id()
- By.name()
- By.tagName()
- By.className()
- By.linkText()
- By.partialLinkText()
- By.xpath
- By.cssSelector()
What is the command that is used in order to display the values of a variable into the output console or log?
Ans: To display a constant string, the command can be used echo <constant string> To display the value of a variable you can use the command like echo ${variable name>> Above is using PHP. If you are using Java, replace echo with System.out.println
Explain how you can use a recovery scenario with Selenium?
Ans: Recovery scenarios depend upon the programming language you use. If you are using Java, then you can use exception handling to overcome same. By using “Try Catch Block” within your Selenium WebDriver Java tests
Explain how to iterate through options in the test script?
Ans: To iterate through options in test script you can loop features of the programming language, for example to type different test data in a text box you can use “for” loop in Java
// test data collection in an array
String[ ] testData = { “test1” , “test2” , “test3” } ;
// iterate through each test data
For (string s: test data) { selenium.type ( “elementLocator”, testData) ; }
How can you prepare customized html report using TestNG in a hybrid framework?
Ans: There are three ways
- Junit: With the help of ANT
- TestNG: Using inbuilt default.html to get the HTML report. Also, XST reports from ANT, Selenium, TestNG combinations Using our customised reports using XSL jar for converting XML content to HTML
From your test script, how you can create an HTML test report?
Ans: To create an HTML test report there are three ways
- TestNG: Using inbuilt default.html to get the HTML report. Also, XLST reports from ANT, Selenium, TestNG combination
- JUnit: With the help of ANT Using our customised reports using XSL jar for converting XML content to HTML
Explain how you can insert a breakpoint in Selenium IDE?
Ans: In Selenium IDE to insert a breakpoint
- Select “Toggle breakpoint” by right click on the command in Selenium IDE
- Press “B” on the keyboard and select the command in Selenium IDE
- Multiple breakpoints can be set in Selenium IDE
Explain in Selenium IDE how can you debug the tests?
Ans: Insert a breakpoint from the location from where you want to execute a test step by step
- Run the test case
- At the given breakpoint execution will be paused
- To continue with the next statement click on the blue button
- Click on the “Run” button to continue executing all the commands at a time
What is Selenese, and what are the types of Selenese?
Ans: Selenese is a selenium set of command which are used for running the test There are three types of Selenese
- Actions: It is used for performing the operations and interactions with the target elements
- Assertions: It is used as checkpoints
- Accessors: It is used for storing the values in a variable
Explain what the limitations of Selenium IDE are?
Ans: The limitations of Selenium IDE
- Exceptional handling is not present
- Selenium IDE uses only HTML languages
- External databases reading is not possible with IDE
- Reading from the external files like .txt, .xls is not possible
- Conditional or branching statements execution as if, else, select statements is not possible
What are the two modes of views in Selenium IDE?
Ans: Either Selenium IDE can be opened as a pop-up window or in a sidebar
In selenium IDE, what are the element locators that can be used to locate elements on a web page?
Ans: In selenium, there are mainly 4 locators that are used
- X-path locators
- CSS locators
- Html id
- Html name
In Selenium IDE, how you can generate random numbers and dates for test data?
Ans: In Selenium IDE you can generate random numbers by using JavaScript
type
css=input#s
javascript{Math.random()}
And for
type
css=input#s
javascript{new Date()}
How you can convert any Selenium IDE tests from Selenese to another language?
Ans: You can use the format option of Selenium IDE to convert tests into another programming language
Using Selenium IDE is it possible to get data from a particular HTML table cell?
Ans: You can use the “storeTable” command
Example store text from cell 0,2 from an HTML table
storeTable
Css=#table 0.2
text from cell
Explain what can cause a Selenium IDE test to fail?
Ans:
- When a locator has changed, and Selenium IDE cannot locate the element
- When element Selenium IDE waiting to access did not appear on the web page, and the operation timed out
- When element Selenium IDE was trying to access was not created
Explain how you can debug the tests in Selenium IDE?
Ans: Insert a breakpoint from the location where you want to execute step by step
- Run the test case
- At the given breakpoint execution will be paused
- To continue with the next step click on the Blue button
- To run commands at a time click on the run button
From Selenium IDE, how you can execute a single line?
Ans: From Selenium IDE single line command can be executed in two ways
- Select “Execute this command” by right-clicking on the command in Selenium IDE
- Press “X” key on the keyboard after selecting the command in Selenium IDE
In which format does source view show your script in Selenium IDE?
Ans: In Selenium IDE source view shows your script in XML format
Explain how you can insert a start point in Selenium IDE?
Ans: In two ways selenium IDE can be set
- Press “S” key on the keyboard and select the command in Selenium IDE
- In Selenium IDE, right-click on the command and then select “Set / Clear Start Point.”
What if you have written your element locator, and how would you test it?
Ans: To test the locator one can use “Find Button” of Selenium IDE, as you click on it, you would see on a screen an element being highlighted provided your element locator is right or-or else an error message will be displayed
What are regular expressions? How can you use regular expressions in Selenium?
Ans: A regular expression is a special text string used for describing a search pattern. In Selenium IDE, a regular expression can be used with the keyword- regexp: as a prefix to the value and patterns needs to be included in the expected values.
What is the core extension?
Ans: If you want to “extend” the default functionality provided by Selenium Function Library, you can create a Core Extension. They are also called “User Extension”. You can even download the ready-made Core Extension created by other Selenium enthusiasts.
How will you handle working with multiple windows in Selenium?
Ans: We can use the command selectWindow to switch between windows. This command uses the title of Windows to identify which window to switch to.
How will you verify the specific position of a web element
Ans: You can use verifyElementPositionLeft & verifyElementPositionTop. It does a pixel comparison of the position of the element from the Left and Top of the page respectively
How can you retrieve the message in an alert box?
Ans: You can use the storeAlert command which will fetch the message of the alert pop up and store it in a variable.
What is Selenium RC (Remote Control)?
Ans:
- Selenium IDE has limitations in terms of browser support and language support. By using Selenium, RC limitation can be diminished. On different platforms and different web browser for automating web application, selenium RC is used with languages like Java, C#, Perl, Python
- Selenium RC is a java based and using any language it can interact with the web application
Using server, you can bypass the restriction and run your automation script running against any web application
Why is Selenium RC used?
Ans: Selenium IDE does not directly support many functions like condition statements, Iteration, logging and reporting of test results, unexpected error handling, and so on as IDE supports only HTML language. To handle such issues, Selenium RC has used it supports the language like Perl, Ruby, Python, PHP using these languages we can write the program to achieve the IDE issues.
Explain what the main difference between web-driver and RC is?
Ans: The main difference between Selenium RC and Webdriver is that selenium RC injects javascript function into browsers when the page is loaded. On the other hand, Selenium Webdriver drives the browser using browsers built-in support
What are the advantages of RC?
Ans: Advantages of RC are
- Can read or write data from/ to .xls, .txt, etc
- It can handle dynamic objects and Ajax-based UI elements
- Loops and conditions can be used for better performance and flexibility
- Support many Programming Languages and Operating Systems
- For any JAVA script enabled browser Selenium RC can be used
Explain what is a framework, and what are the frameworks available in RC?
Ans: A collection of libraries and classes is known as Framework, and they are helpful when testers have to automate test cases. NUnit, JUnit, TestNG, Bromine, RSpec, unit test are some of the frameworks available in RC
How can we handle pop-ups in RC?
Ans: To handle pop-ups in RC, using the selectWindow method, a pop-up window will be selected, and windowFocus method will let the control from the current window to pop-up windows and perform actions according to script
What are the technical limitations while using Selenium RC?
Ans: Apart from the “same-origin policy” restriction from js, Selenium is also restricted from exercising anything that is outside the browser.
Can we use Selenium RC to drive tests on two different browsers on one operating system without Selenium Grid?
Ans: Yes, it is possible when you are not using JAVA testing framework. Instead of using the Java testing framework if you are using java client driver of selenium, then TestNG allows you to do this. By using “parallel=test” attribute, you can set tests to be executed in parallel and can define two different tests, each using a different browser.
Why use TestNG with Selenium RC?
Ans: If you want full automation against the different server and client platforms, You need a way to invoke the tests from a command-line process, reports that tell you what happened and flexibility in how you create your test suites. TestNG gives that flexibility.
Explain how you can capture the server-side log Selenium Server?
Ans: To capture the server-side log in Selenium Server, you can use the command
java –jar .jar –log selenium.log
Other than the default port 4444 how you can run Selenium Server?
Ans: You can run Selenium server on java-jar selenium-server.jar-port other than its default port
How Does Selenium grid hub keep in touch with RC slave machine?
Ans: At predefined time selenium grid hub keeps polling all RC slaves to make sure it is available for testing. The deciding parameter is called “remoteControlPollingIntervalSeconds” and is defined in “grid_configuration.yml” file
Using Selenium, how can you handle network latency?
Ans: To handle network latency you can use driver.manage.pageloadingtime for network latency
To enter values into text boxes, what the command that can be used is?
Ans: To enter values into text boxes we can use command sendkeys()
How do you identify an object using selenium?
Ans: To identify an object using Selenium you can use
isElementPresent(String locator)
isElementPresent takes a locator as the argument and if found returns a Boolean
In Selenium, what are Breakpoints and Start points?
Ans:
- Breakpoints: When you implement a breakpoint in your code, the execution will stop right there. This helps you to verify that your code is working as expected.
- Start points: Startpoint indicates the point from where the execution should begin. The start point can be used when you want to run the test script from the middle of the code or a breakpoint.
Mention why to choose Python over Java Selenium?
Ans: Few points that favour Python over Java to use with Selenium is,
- Java programs tend to run slower compared to Python programs.
- Java uses traditional braces to start and ends blocks, while Python uses indentation.
- Java employs static typing, while Python is dynamically typed.
- Python is simpler and more compact compared to Java.
Mention what are the challenges in Handling Ajax Call in Selenium Webdriver?
Ans: The challenges faced in Handling Ajax Call in Selenium Webdriver are Using “pause” command for handling Ajax call is not completely reliable. Long pause time makes the test unacceptably slow and increases the testing time. Instead, “waitforcondition” will be more helpful in testing Ajax applications. It is difficult to assess the risk associated with particular Ajax applications Given full freedom to developers to modify Ajax application makes the testing process challenging Creating automated test request may be difficult for testing tools as such AJAX application often use different encoding or serialisation technique to submit POST data.
Mention what IntelliJ is?
Ans: IntelliJ is an IDE that helps you to write better and faster code for Selenium. IntelliJ can be used in the option to Java bean and Eclipse.
Mention in what ways you can customise TestNG report?
Ans: You can customise the TestNG report in two ways,
- Using ITestListener Interface
- Using IReporter Interface
To generate pdf reports mention what Java API is required?
Ans: To generate pdf reports, you need Java API IText.
Mention what Listeners are in Selenium WebDriver?
Ans: In Selenium WebDriver, Listeners “listen” to the event defined in the selenium script and behave accordingly. It allows customising TestNG reports or logs. There are two main listeners, i.e. WebDriver Listeners and TestNG Listeners.
Mention what are the types of Listeners in TestNG?
Ans: The types of Listeners in TestNG are,
- IAnnotationTransformer
- IAnnotationTransformer2
- IConfigurable
- IConfigurationListener
- IExecutionListener
- IHookable
- IInvokedMethodListener
- IInvokedMethodListener2
- IMethodInterceptor
- IReporter
- ISuiteListener
- ITestListener
Mention what desired capability is? How is it useful in terms of Selenium?
Ans: The desired capability is a series of key/value pairs that stores the browser properties like browser name, browser version, the path of the browser driver in the system, etc. to determine the behaviour of the browser at runtime.
For Selenium, It can be used to configure the driver instance of Selenium WebDriver when you want to run the test cases on a different browser with different operating systems and versions.
For Database Testing in Selenium Webdriver what API is required?
Ans: For Database Testing in Selenium Webdriver, you need JDBC (Java Database Connectivity) API. It allows you to execute SQL statements.
Mention when to use AutoIT?
Ans: Selenium is designed to automate web-based applications on different browsers. But to handle window GUI and non-HTML popups in the application you need AutoIT.
Mention why do you need Session Handling while working with Selenium?
Ans: While working with Selenium, you need Session Handling. This is because, during test execution, the Selenium WebDriver has to interact with the browser all the time to execute given commands. At the time of performance, it is also possible that, before the current execution completes, someone else starts execution of another script, in the same machine and the same type of browser. So to avoid such a situation, you need Session Handling.
Mention what the advantages of Using Git Hub For Selenium are?
Ans: The advantages of Using Git Hub for Selenium are Multiple people when they work on the same project they can update project details and inform other team members simultaneously. Jenkins can help you to build the project from the remote repository regularly. This helps you to keep track of failed builds.
What is Automation Testing?
Ans: Automation testing or Test Automation is a process of automating the manual process to test the application/system under test. Automation testing involves the use of a separate testing tool which lets you create test scripts which can be executed repeatedly and doesn’t require any manual intervention.
What are the benefits of Automation Testing?
Ans: Benefits of Automation testing are:
- Supports execution of repeated test cases
- Aids in testing a large test matrix
- Enables parallel execution
- Encourages unattended execution
- Improves accuracy thereby reducing human-generated errors
- Saves time and money
Why should Selenium be selected as a test tool?
Ans: Selenium is a free and open-source have a large user base and helping communities have cross Browser compatibility (Firefox, Chrome, Internet Explorer, Safari etc.) have great platform compatibility (Windows, Mac OS, Linux etc.) supports multiple programming languages (Java, C#, Ruby, Python, Pearl etc.) has fresh and regular repository developments supports distributed testing
What is Selenium? What are the different Selenium components?
Ans: Selenium is one of the most popular automated testing suites. Selenium is designed in a way to support and encourage automation testing of functional aspects of web-based applications and a wide range of browsers and platforms. Due to its existence in the open-source community, it has become one of the most accepted tools amongst the testing professionals. Selenium is not just a single tool or a utility, rather a package of several testing tools and for the same reason, it is referred to as a Suite. Each of these tools is designed to cater to different testing and test environment requirements. The suite package constitutes the following sets of tools:
- Selenium Integrated Development Environment (IDE) – Selenium IDE is a record and playback tool. It is distributed as a Firefox Plugin.
- Selenium Remote Control (RC) – Selenium RC is a server that allows a user to create test scripts in the desired programming language. It also allows executing test scripts within the large spectrum of browsers.
- Selenium WebDriver – WebDriver is a different tool altogether that has various advantages over Selenium RC. WebDriver directly communicates with the web browser and uses its native compatibility to automate.
- Selenium Grid – Selenium Grid is used to distribute your test execution on multiple platforms and environments concurrently.
What are the testing types that can be supported by Selenium?
Ans: Selenium supports the following types of testing:
Functional Testing
Regression Testing
What are the limitations of Selenium?
Ans: Following are the limitations of Selenium:
- Selenium supports the testing of only web-based applications
- Mobile applications cannot be tested using Selenium
- Captcha and Barcode readers cannot be tested using Selenium
- Reports can only be generated using third-party tools like TestNG or Junit.
- Selenium is a free tool. Thus there is no ready vendor support through the user can find numerous helping communities.
- A user is expected to possess prior programming language knowledge.
When should I use Selenium IDE?
Ans: Selenium IDE is the simplest and easiest of all the tools within the Selenium Package. Its record and playback feature make it exceptionally easy to learn with minimal acquaintances to any programming language. Selenium IDE is an ideal tool for a naïve user.
What is Selenese?
Ans: Selenese is the language which is used to write test scripts in Selenium IDE.
What are the different types of locators in Selenium?
Ans: Locator can be termed as an address that identifies a web element uniquely within the webpage. Thus, to identify web elements accurately and precisely, we have different types of locators in Selenium:
- ID
- ClassName
- Name
- TagName
- LinkText
- PartialLinkText
- Xpath
- CSS Selector
- DOM
What is the difference between Assert and verify commands?
Ans:
- Assert: Assert command checks whether the given condition is true or false. Let’s say we assert whether the given element is present on the web page or not. If the condition is true, then the program control will execute the next test step, but if the condition is false, the execution will stop, and no further test would be executed.
- Verify: Verify command also checks whether the given condition is true or false. Irrespective of the condition being true or false, the program execution doesn’t halt, i.e. any failure during verification would not stop the execution, and all the test steps would be executed.
What is an XPath?
Ans: XPath is used to locate a web element based on its XML path. XML stands for Extensible Markup Language and is used to store, organise and transport arbitrary data. It stores data in a key-value pair which is very much similar to HTML tags. Both being markup languages and since they fall under the same umbrella, XPath can be used to locate HTML elements.
The fundamental behind locating elements using XPath is the traversing between various elements across the entire page and thus enabling a user to find an element with the reference of another element.
What is the difference between “/” and “//” in XPath?
Ans:
- Single Slash “/” – Single slash is used to create XPath with an 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 a relative path, i.e. the XPath would be created to start selection from anywhere within the document.
What is the Same-origin policy and how it can be handled?
Ans: The problem of same-origin policy disallows to access the DOM of a document from an origin that is different from the origin we are trying to access the document.
Origin is a sequential combination of scheme, host, and port of the URL. For example, for a URL HTTP:// http://www.softwaretestingo.com/selenium/, the origin is a combination of HTTP, softwaretestingo.com, 80 correspondingly.
Thus the Selenium Core (JavaScript Program) cannot access the elements from an origin that is different from where it was launched. For Example, if I have launched the JavaScript Program from “http://www.softwaretestingo.com”, then I would be able to access the pages within the same domain such as “http://www.softwaretestingblog.in/selenium” or “http://www.softwaretestingo.com/manual/”. The other domains, like google.com, seleniumhq.org would no more be accessible.
So, To handle the same-origin policy, Selenium Remote Control was introduced.
When should I use Selenium Grid?
Ans: Selenium Grid can be used to execute same or different test scripts on multiple platforms and browsers concurrently to achieve distributed test execution, testing under different environments and saving execution time remarkably.
What do we mean by Selenium 1 and Selenium 2?
Ans: Selenium RC and WebDriver, in a combination, are popularly known as Selenium 2. Selenium RC alone is also referred to as Selenium 1.
Which is the latest Selenium tool?
Ans: WebDriver
How do I launch the browser using WebDriver?
Ans: The following syntax can be used to launch Browser:
WebDriver driver = new FirefoxDriver();
WebDriver driver = new ChromeDriver();
WebDriver driver = new InternetExplorerDriver();
What are the different types of Drivers available in WebDriver?
Ans: The different drivers available in WebDriver are:
- FirefoxDriver
- InternetExplorerDriver
- ChromeDriver
- SafariDriver
- OperaDriver
- AndroidDriver
- IPhoneDriver
- HtmlUnitDriver
What are the different types of waits available in WebDriver?
Ans: There are two types of waits available in WebDriver:
Implicit Wait
Explicit Wait
- Implicit Wait: Implicit waits are used to provide a default waiting time (say 30 seconds) between each consecutive test step/command across the entire test script. Thus, the subsequent test step would only execute when the 30 seconds have elapsed after executing the previous test step/command.
- Explicit Wait: Explicit waits are used to halt the execution until the time a particular condition is met or the maximum time has elapsed. Unlike Implicit waits, explicit waits are applied for a particular instance only.
How to type in a textbox using Selenium?
Ans: User can use sendKeys(“String to be entered”) to enter the string in the textbox.
Syntax:
WebElement username = drv.findElement(By.id(“Email”));
// entering username
username.sendKeys(“sth”);
How can you find if an element in displayed on the screen?
Ans: 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()
isSelected()
isEnabled()
Syntax:
- isDisplayed():
boolean buttonPresence = driver.findElement(By.id(“gbqfba”)).isDisplayed();
- isSelected():
boolean buttonSelected = driver.findElement(By.id(“gbqfba”)).isDisplayed();
- isEnabled():
boolean searchIconEnabled = driver.findElement(By.id(“gbqfb”)).isEnabled();
How can we get a text of a web element?
Ans: Get command is used to retrieve the inner text of the specified web element. The command doesn’t require any parameter but returns a string value. It is also one of the extensively used commands for verification of messages, labels, errors etc. displayed on the web pages.
Syntax:
String Text = driver.findElement(By.id(“Text”)).getText();
How to select value in a dropdown?
Ans: Value in the dropdown can be selected using WebDriver’s Select class.
Syntax:
- selectByValue:
Select selectByValue = new Select(driver.findElement(By.id(“SelectID_One”))); selectByValue.selectByValue(“greenvalue”);
- selectByVisibleText:
Select selectByVisibleText = new Select (driver.findElement(By.id(“SelectID_Two”))); selectByVisibleText.selectByVisibleText(“Lime”);
- selectByIndex:
Select selectByIndex = new Select(driver.findElement(By.id(“SelectID_Three”))); selectByIndex.selectByIndex(2);
What are the different types of navigation commands?
Ans: Following are the navigation commands:
- navigate().back() – The above command requires no parameters and takes back the user to the previous webpage in the web browser’s history.
Sample code:
driver.navigate().back(); - navigate().forward() – This command lets the user to navigate to the next web page with reference to the browser’s history.
Sample code:
driver.navigate().forward(); - navigate().refresh() – This command lets the user to refresh the current web page there by reloading all the web elements.
Sample code:
driver.navigate().refresh(); - navigate().to() – This command lets the user to launch a new web browser window and navigate to the specified URL.
Sample code:
driver.navigate().to(“https://google.com”);
How to click on a hyperlink using linkText?
Ans: driver.findElement(By.linkText(“Google”)).click();
The command finds the element using link text and then click on that element, and thus the user would be re-directed to the corresponding page.
The above-mentioned link can also be accessed by using the following command.
driver.findElement (By.partialLinkText(“Goo”)).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 with the specified substring and then clicks on it.
How to handle frame in WebDriver?
Ans: An inline frame acronym as iframe is used to insert another document within the current HTML document or simply a web page into a web page by enabling nesting.
- Select iframe by id
driver.switchTo().frame(“ID of the frame“); - Locating iframe using tagName
driver.switchTo().frame (driver.findElements (By.tagName(“iframe”).get(0)); - Locating iframe using index
frame(index)
driver.switchTo().frame(0); - frame(Name of Frame)
driver.switchTo().frame(“name of the frame”);
frame(WebElement element)
Select Parent Window
driver.switchTo().defaultContent();
When do we use findElement() and findElements()?
Ans:
findElement(): findElement() is used to find the first element in the current web page matching the specified locator value. Take note that only the first matching element would be fetched.
Syntax:
WebElement element = driver.findElements(By.xpath(“//div[@id=’example’]//ul//li”));
findElements(): findElements() is used to find all the elements in the current web page matching to the specified locator value. Take a note that all the matching elements would be fetched and stored in the list of WebElements.
Syntax:
List <WebElement> elementList = driver.findElements(By.xpath(“//div[@id=’example’]//ul//li”));
How to find more than one web element in the list?
Ans: At times, we may come across elements of the same type of multiple hyperlinks, images etc. arranged in an ordered or unordered list. Thus, it makes absolute sense to deal with such elements by a single piece of code, and this can be done using the WebElement List.
Sample Code
// Storing the list List <WebElement> elementList = driver.findElements(By.xpath("//div[@id='example']//ul//li")); // Fetching the size of the list int listSize = elementList.size(); for (int i=0; i<listSize; i++) { // Clicking on each service provider link serviceProviderLinks.get(i).click(); // Navigating back to the previous page that stores link to service providers driver.navigate().back(); }
What is the difference between driver.close() and driver.quit command?
Ans:
- Close (): WebDriver’s close() method closes the web browser window that the user is currently working on or we can also say the window that is being currently accessed by the WebDriver. The command neither requires any parameter, nor does it return any value.
- Quit (): Unlike a close() method, quit() method closes down all the windows that the program has opened. The same as the close() method, the command neither requires any parameter nor does it return any value.
Can Selenium handle windows based pop up?
Ans: Selenium is an automation testing tool which supports only web application testing. Therefore, windows pop up cannot be handled using Selenium.
How can we handle web-based pop-up?
Ans: WebDriver offers the users with a very efficient way to handle these pop-ups using Alert interface. There are four methods that we would be using along with the Alert interface.
- Void dismiss() – The accept() method clicks on the “Cancel” button as soon as the pop-up window appears.
- Void accept() – The accept() method clicks on the “Ok” button as soon as the pop-up window appears.
- String getText() – The getText() method returns
Leave a Reply