A pragmatic approach to QA and OPS

Selenium Questions – Exceptions

This is a list of some questions that can be asked related to Selenium exceptions. Posted on LinkedIn here

1. Why do I sometimes get the ElementClickInterceptedException exception?

Ans : If the element that the script is trying to click is obscured by any other element, then this exception occurs.

2. There is a checkbox in the page, covered with a temporary overlay – if you try to interact with the element before the temporary overlay is removed, what exception will Selenium throw?

Ans: In case you try to interact with the element before the overlay is removed, chances are you will get ElementNotInteractable exception

3. There is a drop down where there are two elements which are disabled. If I try to select the disabled option, what is the exception that will be thrown?

Ans: In this case, Selenium will throw the ElementNotSelectable exception.

4. An element which has display:none was clicked in a test script – will there be any exception triggered?

Ans: In case the element is hidden using the display:none attribute, you should get the ElementNotVisibleException exception

5. If I am navigating to a website which has an expired TLS certificate, will Selenium throw any exception? Why?

Ans: In this case InsecureCertificateException will be thrown. The reason is that Web browsers prevent and block traffic to domains with broken certificates since the communication with the server would be compromised. As such Selenium would be blocked from accessing traffic to that domain. Although this can be bypassed.

6. I’ve passed driver.get(“www.abcd.com“) – what is the exception that will be thrown by Selenium?

Ans: Selenium will throw an InvalidArgumentException in this case. Replacing url with https://www.abcd.com is the right way to fix this particular scenario.

7. If I am using a Selenium version which is not compatible with Chromedriver, what is the exception that Selenium will throw?

Ans: n case of incompatibility between browser and Chromedriver version, Selenium will most likely be not be able to create a new webdriver session. So Selenium will throw SessionNotCreatedException in this scenario.

8. There is an exception InvalidSessionIdException in Selenium? Can you tell me what would be the condition when this exception will be triggered.

Ans: f you’re trying to access a session that has already been destroyed or is invalid, then this exception will be thrown. An example would be trying to do a driver.get(url) after the driver.quit() or driver.close() method has been called

9. Given this html

td class="rcbInputCell rcbInputCellLeft" style="width:100%;">
<input id="ctl00_MainContent_ddlLocale_Input" class="rcbInput ui-widget-  content" type="text" value="Austria: Vienna"   name="ctl00$MainContent$ddlLocale" autocomplete="off"/>

When trying to automate with this code

Select dropdown = new 
   dropdown.selectByValue("Austria: Vienna");

Selenium will throw an exception. What will be the exception that will be thrown.

Ans: This will throw an UnexpectedTagNameException exception since you’re trying the Select class on the element which is an input.

10. The result of driver.current_url in a test script is `https://abcd.com`. If I try to set a cookie for `https://xyz.com` in the same test script, Selenium will throw an exception. What is that exception?

Ans: When trying to set a cookie for a domain other than current domain, Selenium will throw InvalidCookieDomainException.

%d bloggers like this: