Selenium Interview Questions For 2024
Selenium Interview Questions For 2024
Selenium Interview Questions For 2024
driver.findElement(By.linkText(“Today’s deals”)).click();
The command finds the element using link text and then clicks on that element, where after
the user would be redirected to the corresponding page.
driver.findElement(By.partialLinkText(“Service”)).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.
General syntax:
executeScript("window.scrollBy(x-pixels,y-pixels)");
driver.get(“https://www.amazon.com”);
js.executeScript("window.scrollBy(0,1000)");
if(actualTitle.equalsIgnoreCase(expectedTitle))
System.out.println("Title Matched");
else
Alternatively,
Assert.assertEquals(actualTitle, expectedTitle);
Actions class utility is used to hover over a web element in Selenium WebDriver
General Syntax:
Example:
driver.findElement(By.id(“email“)).getCssValue(“font-size”);
No, Selenium cannot automate Captcha. Well, the whole concept of Captcha is to ensure that
bots and automated programs don’t access sensitive information - which is why, Selenium
cannot automate it. The automation test engineer has to manually type the captcha while
other fields can be filled automatically.
Selenium was designed to handle web applications. Windows-based features are not natively
supported by Selenium. However, third-party tools like AutoIT, Robot, etc can be integrated
with Selenium to handle pop-ups and other Windows-based features.
Selenium is an open-source and free automation testing tool, while QTP is a licensed tool that
requires a considerable investment. Selenium supports multiple programming languages and
is cross-platform compatible.
A data-driven framework is a test automation framework that separates the test data from the
test script. It allows testers to write automated tests in a way that is independent of the test
data.
getwindowhandle() method returns the unique identifier of the current browser window,
while getwindowhandles() method returns a set of unique identifiers of all the browser
windows opened by WebDriver.
A Selenium Maven project is a software project that uses Maven to manage the project's
dependencies and build process.
An Object Repository is a centralized location where testers can store all the web elements,
such as buttons, text boxes, and links, used in the test automation framework.
jse.executeScript("document.getElementById(‘email').value=“[email protected]”);
Select class in WebDriver is used for selecting and deselecting options in a dropdown.
The objects of Select type can be initialized by passing the dropdown webElement as a
parameter to its constructor.
dropdown.selectByIndex(5);
selectByValue: Selection based on value
dropdown.selectByValue(“Books”);
selectByVisibleText: Selection of option that displays text matching the given argument
dropdown.selectByVisibleText(“The Alchemist”);
switchTo() command is used to switch between windows, frames or pop-ups within the
application. Every window instantiated by the WebDriver is given a unique alphanumeric
value called “Window Handle”.
driver.switchTo().window(handle);
Alternatively
{ driver.switchTo().window(handle); }
You can achieve this by using sendkeys() or Robot class method. Locate the text box and set
the file path using sendkeys() and click on submit button
browse.sendKeys("D:\\SeleniumInterview\\UploadFile.txt");
driver.manage().window().maximize();
driver.manage().window().setSize(d);
Alternatively,
((JavascriptExecutor)driver).executeScript("window.resizeTo(1024, 768)");
findElement() is used to access any single element on the web page. It returns the object of
the first matching element of the specified locator.
General syntax:
General syntax:
The user can use this feature to handle exceptions by clicking the pause icon on the top right
corner of the IDE. When the script finds an exception it pauses at that particular statement
and enters a debug mode. The entire test case does not fail and hence the user can rectify the
error immediately.
Single slash is used to create Xpath with an absolute path i.e. the XPath would be created to
start selection from the start node.
/html/body/div[2]/div[1]/div[1]/a
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
//div[class="qa-logo"]/a
When we use driver.get() method to navigate to a URL, it will respond with a status of 200-
OK
200 – OK denotes that the link is working and it has been obtained. If any other status is
obtained, then it is an indication that the link is broken.
401 – Unauthorized
As a starter, obtain the links from the web application, and then individually get their status.
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.
verifyLink(url); }
if(httpConn.getResponseCode()!== 200)
System.out.println(“Broken Link”);
With that we have come to the end of the article Seleinium interview questions.
LoadRunner
JMeter
WebLoad
Neoload
Silk Performer
HP Performance Center
Gatling
Apache
Some of the automation tools which could be integrated with Selenium to achieve continuous
testing are:
Jenkins
Travis CI
CircleCI
AWS CodePipeline
Azure DevOps
Bitbucket Pipelines
Assertions are an important part of testing with Selenium, as they enable you to verify that
the state of your application meets your expectations. Without assertions, it would be difficult
to know whether or not your tests are actually passing or failing.
60. Explain the difference between assert and verify
commands.
The assert command is used to check if the given condition is true or not. If the condition is
true, then the execution of the program will continue. If the condition is false, then the
execution of the program will stop.
The verify command is used to check if the given condition is true or not. If the condition is
true, then the execution of the program will continue. If the condition is false, then the
execution of the program will not stop, but an error message will be displayed.
XPath is a language for addressing parts of an XML document. XSLT and other XML-related
technologies use it to access data within XML documents. XPath can be used to navigate
through elements and attributes in an XML document. XPath is a major element in the XSLT
standard and is crucial for processing XML documents.
XPath has two main types of expressions: absolute and relative. Absolute expressions always
start with a forward slash (/), which indicates the root element of the document. Relative
expressions do not start with a forward slash, and are relative to the current context.
Attributes are another important part of XPath. Attributes are added to elements and can
contain valuable information about that element. In order to access an attribute, you must use
the at sign (@) followed by the attribute name.
The difference between "/" and "//" in XPath is that "/" is used to select an element based on
its absolute location, while "//" is used to select an element based on its relative location.
For example, if you want to select the first <p> element on a page, you would use "/p". If you
want to select all <p> elements on a page, regardless of their location, you would use "//p".
What are the WebDriver supported Mobile Testing Drivers?
2. IPhoneDriver is used to test iOS applications. It can only be used on real devices.
There is a difference between type keys and type commands in computer programming. Type
keys are specific characters that you type on the keyboard, while type commands are
instructions given to the computer.
The "type" command is used to enter text into a field on a web page. The "typeAndWait"
command also enters text into a field, but it waits for the page to load before proceeding to
the next command. This can be useful if you are unsure whether or not the text you entered
will cause the page to refresh.
The main difference between the "type" and "typeAndWait" command is that the "type"
command does not wait for the page to reload, while the "typeAndWait" command does. If
you are unsure whether or not the text you are entering will cause the page to refresh, it is
best to use the "typeAndWait" command. This way, you can be sure that the next command
will not be executed until the page has finished loading.
67. What is the main disadvantage of implicit wait?
The main disadvantage of implicit wait is that it can slow down your tests. This is because,
by default, the implicit wait time is set to zero. As such, if an element is not found
immediately, your test will keep trying to find it for the duration of the implicit wait time.
This can add a significant amount of time to your test suite. Another disadvantage of implicit
wait is that it can cause your tests to fail if the element you are waiting for takes longer to
appear than the implicit wait time. Finally, implicit wait can make your tests less reliable
because they can introduce flakiness.
We can launch different browsers in Selenium WebDriver using several methods. For
example, we can use the setWebDriver() method to specify the path to the browser's
executable file. Alternatively, we can use the addCustomProfilePreference() method to add a
custom profile preference for the browser. Finally, we can use the launchBrowser() method to
launch the browser.
public FirefoxDriver() {
this.driver.get(url);
}
Assuming that you have already downloaded and installed Firefox, the next thing you need to
do is write a code snippet to launch Firefox browser in WebDriver. The code snippet for
launching Firefox browser is given below:
driver.get("http://www.google.com");
driver.get(url);
wait.until(ExpectedConditions.titleContains("Google"));
driver.quit();
This code snippet will launch the Chrome browser, navigate to Google.com, and then print
the page title to the console.
To launch Internet Explorer browser in WebDriver, you can use the following code snippet:
WebDriver driver = new InternetExplorerDriver();
driver.get("http://www.google.com");
This will launch the Internet Explorer browser and navigate to the Google homepage.
When using WebDriver, you can perform drag and drop operations using the Actions class.
This class has a number of methods that can be used to perform various actions, such as
clicking, dragging, and dropping. In order to use the Actions class, you first need to
instantiate it with a WebDriver instance:
Once you have an Actions instance, you can use the dragAndDrop() method to perform a
drag and drop operation. This method takes two WebElements as arguments: the element
toDrag, and the element toDrop. For example, to drag an element with the id "draggable" and
drop it on an element with the id "droppable", you would do the following:
actions.dragAndDrop(draggable, droppable).perform();
You can also use the clickAndHold() and release() methods to perform a drag and drop
operation. The clickAndHold() method takes a WebElement as an argument and "grabs" it,
while the release() method releases the element. For example:
actions.clickAndHold(draggable).release(droppable).perform();
You can also chain together multiple Actions methods to create more complex interactions.
For example, the following code will first move to the draggable element, then click and hold
it, move to the droppable element, and finally release it:
actions.moveToElement(draggable).clickAndHold().moveToElement(droppable).release().pe
rform();
There are a couple of ways to refresh a web page in WebDriver. The most common method is
to use the "Refresh" button in the browser toolbar. Alternatively, you can also use the
keyboard shortcut for refresh, which is typically F5. Finally, you can also right-click on the
page and select "Refresh" from the context menu. All of these methods will cause the page to
reload and any changes that have been made will be lost.
If you want to refresh the page without losing any changes, you can use the "Reload" button
in the browser toolbar. This will reload the page from the server without losing any changes
that have been made. Alternatively, you can also use the keyboard shortcut for reload, which
is typically Shift+F5. Finally, you can also right-click on the page and select "Reload" from
the context menu. All of these methods will cause the page to reload without losing any
changes that have been made.
When using WebDriver, you can launch applications by either calling the "get" method on
the driver instance, or by using the "navigate" method. Applications can also be invoked
using a third-party tool such as Selenium IDE. However, doing so requires that you have the
URL of the application to be launched beforehand. When using the "get" method, you simply
need to pass in the URL of the application as a string.
Automation testing can be a great way to speed up the software testing process. By
automating certain tests, you can save time and resources that would otherwise be spent on
manual testing. Additionally, automation can help to improve the accuracy of your tests, as
well as provide detailed reports that can help you to identify any areas that need further
attention. Overall, automation testing can be a valuable tool for any software development
team.
Is there an HtmlUnitDriver for .NET?
Yes.
There are a few ways to redirect browsing from a browser through some proxy. One way is to
use a web proxy. Web proxies can be used to access websites that may be blocked by your
network administrator. Another way to redirect browsing is to use a Virtual Private Network
(VPN). VPNs can be used to encrypt your traffic and route it through a proxy server. Finally,
you can use a browser extension to redirect your traffic. Browser extensions are useful if you
want to bypass proxy servers that are configured in your network settings.
The pause feature in Selenium IDE allows the tester to add a pause between the execution of
two commands. It is used to slow down the test execution to allow for better observation of
the test execution flow.
Test listeners: It listens to the test execution and allows us to perform actions
before or after a test case is executed.
Suite listeners: It listens to the suite execution and allows us to perform actions
before or after the suite is executed.
Method listeners: It listens to the execution of individual test methods and allows
us to perform actions before or after a test method is executed.
81. Mention important details of different types of
frameworks and also regarding the connection of Selenium
with Robot Framework
Different sets of frameworks are available which can be used with Selenium:
Data-Driven Framework: It uses external data sources such as CSV or Excel files
to drive the test execution.
Selenium can be connected with Robot Framework using the Selenium2Library. The
Selenium2Library is a Robot Framework test library that allows us to control web browsers
using Selenium WebDriver.
These are servers to automate the software development process. Using Jenkins with
Selenium provides the following benefits:
Automatic triggering of Selenium tests when code changes are committed to the
repository.
Integration with other tools such as JIRA, GitHub, and Slack to provide
notifications and status updates.
Dynamic web elements can be handled using different methods such as xpath, CSS selectors,
and the Explicit wait mechanism in Selenium. You can use these methods to locate the
dynamic elements and perform actions on them.
You can simulate the browser back button click in Selenium using the navigate().back()
method. This method will navigate back to the previous page in the browser history.
Alerts can be handled using the Alert interface in Selenium. You can switch to the alert using
the switchTo().alert() method and perform actions such as accepting or dismissing the alert
using the accept() or dismiss() methods.
driver.find_element(By.CSS_SELECTOR, "#element_id")
Thread.sleep()
element.clear()
91. Which of the following methods is used to maximize the
browser window in Selenium?
driver.maximize_window()