Selenium Interview Question
Selenium Interview Question
1. What is Selenium?
- Selenium WebDriver
- Selenium Grid
3. What is WebDriver?
Advantages:
Disadvantages:
The WebDriver sends commands (like opening a URL or finding an element) to the
browser through the browser's driver, which converts the commands into HTTP
requests. The browser processes these requests and sends back the results.
WebDriver has a layered architecture where the client library sends commands to the
WebDriver API. These commands are converted into HTTP requests and sent to the
browser driver, which communicates with the actual browser.
driver.get("https://example.com");
Example:
Example:
Example:
Example:
isDisplayed, isEnabled, and isSelected are commonly used to verify the visibility,
interactivity, and selection state of elements.
Navigate back:
driver.navigate().back();
Navigate forward:
driver.navigate().forward();
Example:
driver.navigate().refresh();
get() waits until the page is completely loaded, while navigate.to() can be used for back
and forward navigation and doesn’t wait for the entire page to load.
SELENIUM INTERVIEW QUESTIONS AND ANSWERS (PART 01)
Provide text:
driver.findElement(By.id("inputBox")).sendKeys("text");
Clear text:
driver.findElement(By.id("inputBox")).clear();
Example:
Dropdowns in Selenium WebDriver can be handled using the Select class. The Select
class provides methods to select or deselect options in a dropdown.
The Select class in Selenium WebDriver is used to interact with dropdowns. It provides
methods to select options by visible text, index, or value, and also allows deselecting
options in multi-select dropdowns.
SELENIUM INTERVIEW QUESTIONS AND ANSWERS (PART 01)
You can create a generic method that accepts the WebElement of the dropdown and the
option to select (by text, index, or value). This method can then be reused for different
dropdowns.
Example:
Bootstrap dropdowns are not handled using the Select class since they do not use the
<select> tag. You can handle them by clicking on the dropdown element to reveal the
options and then clicking on the desired option using XPath or CSS selectors.
Example:
driver.findElement(By.id("dropdownButton")).click();
driver.findElement(By.xpath("//a[text()='Option']")).click();
JQuery dropdowns can be handled by first clicking on the dropdown to open it, and then
selecting an option using its XPath or CSS selector.
Example:
driver.findElement(By.id("dropdownButton")).click();
driver.findElement(By.xpath("//li[text()='Option']")).click();
SELENIUM INTERVIEW QUESTIONS AND ANSWERS (PART 01)
To check if dropdown options are sorted, retrieve all the options from the dropdown,
store them in a list, and compare the list with a sorted version of it.
Google Search:
To handle auto-suggest dropdowns like in Google search, send the keys to the search
box and wait for the suggestions to load. Then, select the desired option from the list.
Example:
Bing Search:
Bing search works similarly to Google. You send the keys to the input box and capture
the suggestions.
Example:
SELENIUM INTERVIEW QUESTIONS AND ANSWERS (PART 01)
Example:
To select a specific checkbox, locate it using its XPath, CSS, or another locator strategy
and click on it.
Example:
driver.findElement(By.id("checkboxId")).click();
To select all checkboxes, use a locator that matches all the checkboxes and iterate
through the list of elements, clicking on each one.
Example:
You can select multiple checkboxes by finding their locators and clicking on the specific
checkboxes you want.
Example:
driver.findElement(By.id("checkbox1")).click();
driver.findElement(By.id("checkbox2")).click();
SELENIUM INTERVIEW QUESTIONS AND ANSWERS (PART 01)
You can use the findElements method to retrieve all checkboxes and then select the last
N elements by iterating over the list.
Example:
Similar to selecting the last N checkboxes, but this time you iterate through the first N
elements.