Selenium Webdriver Cheat Sheet



During automation in Selenium, you will come across different selenium exceptions and need to manage them. Regardless of whether you work with other automation testing tools like Katalon Studio, you may still face these types of exception in selenium. They are, but, more effectively fixable than bugs or errors as they can throw logical termination.

Selenium CHEAT SHEET FURTHERMORE: Selenium Testing Training. Firefox WebDriver driver = new FirefoxDriver;. Chrome WebDriver driver = new ChromeDriver;. Internet Explorer WebDriver driver = new SafariDriver;. Safari Driver WebDriver driver = new InternetExplorerDriver; D r i v e r I n i t i a l i z a t i o n B a s i c s.

Automation code execution mostly may not complete as expected because of numerous elements engaged with execution like server stability, Internet issues, network stability issues, and so forth. We may get exceptions in selenium because of inadequate holding up time or erroneous language structures, parameters, and so forth.

This cheat sheet has top common exceptions in selenium webdriver. Above all, we should examine some significant information regarding the term “exception” in Selenium.

  1. Cheat Sheet 6: All Selenium This cheat sheet uses the most frequently used Selenium and Python. It will give you clear instructions for Auto downloading, locating elements, and reading browser details. It has a list of Python Selenium commands for operations on elements including code snippets so you can if you are doing it right.
  2. So, I enjoy using Selenium WebDriver. You can find lots of materials in my WebDriver Series. A big part of the job of writing maintainable and stable web automation is related to finding the proper element's locators. So, I created the first and most exhaustive Selenium WebDriver cheat sheet dedicated to the locators.

What are Selenium Exceptions?

An exception is known as an uncommon or phenomenal event that happens amid the execution of a software program or application. It is a runtime error of an unexpected outcome or event which impact and upset regular program flow. An exception is likewise considered as a fault.

Characterization of Exception in Selenium

Selenium all exceptions is partitioned into two kinds including Checked Exceptions and Unchecked Exceptions.

Checked Exceptions

Checked Exceptions are handled during the way toward composing codes. These exceptions are taken care of before compiling the code, in this manner; such exceptions are analyzed at the compile time.

Unchecked Exceptions

These exceptions are tossed at runtime. Unchecked exceptions are more calamitous than the compile-time exception as it causes issues while running Automation pack in headless.

Common Exceptions in Selenium:

Here is a rundown of probably the most outstanding exceptions in Selenium WebDriver which you might possibly experience.

  • RemoteDriverServerException: This is thrown when the server does not react because of the issue that the abilities portrayed are not proper.
  • ScreenshotException: It is difficult to capture a screen.
  • ScriptTimeoutException: Thrown when executeAsyncScript takes additional time than the given time limit to return the value.
  • SessionNotCreatedException: another session couldn’t be effectively made.
  • SessionNotFoundException: The WebDriver is playing out the activity directly after you quit the program.
  • StaleElementReferenceException: This occurs if the web element is detached from the current DOM.
  • TimeoutException: Thrown when there isn’t sufficient time for a direction to be finished.
  • UnableToCreateProfileException: You can open a program with specific choices utilizing profiles, yet in some cases, another version of Selenium driverserver or program may not support the profiles.
  • WebDriverException: This happens when the WebDriver is performing the activity directly after you close the program.

We have recorded a wide range of selenium exceptions alongside their clarifications above. From here, you can create robust and ideal codes in Selenium just as Katalon Studio by taking care of these exceptions wisely. We trust this blog will be a brisk reference for you to understand exceptions in Selenium.


For Python version the link is here


Install Java

To install Java go to this link


IDE

You can use any text editor. I recommend Eclipse as it is free and have extensive support. For list of popular editors , this are the links


Download Selenium

Download selenium webdriver in this link


Dirty our hands !


Import Selenium



Browsers support (Firefox , Chrome , Internet Explorer, Edge , Opera)

Driver setup:

Chrome:

System.se­tPr­ope­rty­('we­bdr­ive­r.chrome.d­riv­er', “'Pat­h To­ chromedr­ive­r');

To download: Visit Here


Firefox:

System.se­tPr­ope­rty­('we­bdr­ive­r.g­eck­o.d­riv­er', '­Pat­h To­ g­eck­odr­ive­r');

To download: Visit GitHub


Internet Explorer:

System.se­tPr­ope­rty­('we­bdr­ive­r.ie.d­riv­er', 'Pat­h To­ IEDriverServer.exe');

To download: Visit Here

Edge:

System.se­tPr­ope­rty­('we­bdr­ive­r.edge.d­riv­er', 'Pat­h To­ MicrosoftWebDriver.exe');

To download: Visit Here


Opera:

System.se­tPr­ope­rty­('we­bdr­ive­r.opera.d­riv­er', 'Pat­h To­ operadriver');

To download: visit GitHub

Browser Arguments:

–headless

To open browser in headless mode. Works in both Chrome and Firefox browser

–start-maximized

To start browser maximized to screen. Requires only for Chrome browser. Firefox by default starts maximized

–incognito

To open private chrome browser

–disable-notifications

To disable notifications, works Only in Chrome browser

Example:


Alternative


Selenium webdriver cheat sheet download

Launch URL


Retrieve Browser Details:


Navigation


Locating Elements

By id

<input id=”login” type=”text” />


By Class Name

Selenium Webdriver Chrome

<input class=”gLFyf” type=”text” />


By Name

<input name=”z” type=”text” />


By Tag Name

Selenium webdriver cheat sheet examples

<div id=”login” >…</div>


By Link Text

<a href=”#”>News</a>


By XPath

<form id=”login” action=”submit” method=”get”>

Username: <input type=”text” />

Password: <input type=”password” />

</form>


By CSS Selector

<form id=”login” action=”submit” method=”get”>

Username: <input type=”text” />

Password: <input type=”password” />

</form>


Clicking / Input text

Clicking button


Send Text


Waits

Implicit Waits

An implicit wait instructs Selenium WebDriver to poll DOM for a certain amount of time, this time can be specified, when trying to find an element or elements that are not available immediately.


Explicit Waits

Explicit wait make the webdriver wait until certain conditions are fulfilled . Example of a wait


List of explicit waits

  • alertIsPresent()
  • elementSelectionStateToBe()
  • elementToBeClickable()
  • elementToBeSelected()
  • frameToBeAvaliableAndSwitchToIt()
  • invisibilityOfTheElementLocated()
  • invisibilityOfElementWithText()
  • presenceOfAllElementsLocatedBy()
  • presenceOfElementLocated()
  • textToBePresentInElement()
  • textToBePresentInElementLocated()
  • textToBePresentInElementValue()
  • titleIs()
  • titleContains()
  • visibilityOf()
  • visibilityOfAllElements()
  • visibilityOfAllElementsLocatedBy()
  • visibilityOfElementLocated()



Loading a list of elements like li and selecting one of the element



Read Attribute


Get CSS

CSS values varies on different browser, you may not get same values for all the browser.


Capture Screenshot

This will saved the file as in the path of destFile.


Selenium Webdriver Ruby Cheat Sheet

isSelected()

isSelected() method in selenium verifies if an element (such as checkbox) is selected or not. isSelected() method returns a boolean.


isDisplayed()

isDisplayed() method in selenium webdriver verifies and returns a boolean based on the state of the element (such as button) whether it is displayed or not.


isEnabled()

is_enabled() method in selenium python verifies and returns a boolean based on the state of the element (such as button) whether it is enabled or not.

Minimum modules to import


Created : 17 December 2019