Selenium Questions
Selenium Questions
© Copyright by Interviewbit
Contents
16. There are failures in your suite execution, where only a few test cases have
passed. How will you optimize your upcoming test runs in Selenium?
driver.switchTo().frame(2);
While a timeout value is a time taken to wait for a condition, polling frequency is the
frequency to check the success or failure of the condition.
9. Can you explain how you can handle colors in a web driver?
We can use the command getCSSValue(arg0) to fetch the colours by sending the
colour as the argument.
System.setProperty("Service_name", "selenium_java_client");
System.setProperty("Service_host", "localhost");
System.setProperty("Service_port", "14258");
ImmutableCapabilities = new ImmutableCapabilities("browserName", "chrome");
WebDriver driver=new RemoteWebDriver(new URL("http//sample.com"), capabilities);
driver. navigate().refresh()
driver.findElement (By.xpath(“sample”)).click();
You can use a try-catch block within a for loop if the element is not attached to
the DOM
for(int i=0;i<=2;i++)
{ try { driver.findElement(By.xpath("sample")).click();
break; }
Catch (Exception e){
Sysout(e.getMessage());
}
}
If you are sure that the element will be available, use the
ExpectedConditions.refreshed method to avoid the StaleElementReference
exception. This method updates the element by redrawing it and providing
access to the referenced element.
wait.until(ExpectedConditions.refreshed(ExpectedConditions.stalenessOf("sample")));
selenium.captureNetworkTraffic("xml");
From my observation of the test scripts, I find that the .navigateto() method has been
used, which is not advisable in this case. Driver.get commands are perfect for a
website that loads slowly, as it waits for the page to get loaded fully and then
proceeds to the next steps. However, while using driver.navigateto() method, the
driver does not wait for the page to be loaded completely, and many components are
loaded yet, which throws the NoSuchElement exception.
The navigate().forward() command takes you forward by one page (previous page)
on the browser’s history. This method enables the browser to click on the forward
button in the existing browser window.
No, we cannot use assert commands as it halts the further steps of the execution, in
case of an assertion failure. Instead, we can use the verify command in this case.
Verify commands, check the conditions if they are true or false, and also all the test
phases get executed.
23. The Selenium script runs in Chrome but not in IE. What can
be done?
The following steps can be done to fix this issue:
Update the Selenium IE Driver
Verify that the IE driver and working environment are compatible.
Configure the IE driver with the setProperty method and import dependencies.
Set the same value for the ‘Enable Protected Mode’ option for all zones from the
Security tab
Turn off the internet security settings in IE when running the script
Use CSS Selectors to minimize exceptions
Set a registry entry
Avoid declaring the driver instance as static for running scripts on browsers
parallelly.
Use the latest Selenium jars
Enable Javascript on the IE browser.
Try using JavaScriptExecutor instead of a native click when clicking elements.
Conclusion
In this article, we observe that many Selenium-based interview questions for 5+ years
of experienced people are related to troubleshooting, using the right wait
commands, exploring different options to verify a test case etc, generating reports
etc. the Selenium scenario-based interview questions are mostly asked to test your
prowess with the tool all these years. Dive into your practical knowledge of Selenium
and practice various tricky scenarios to grab that job offer!
Useful Resources
Css Interview Questions Laravel Interview Questions Asp Net Interview Questions