Selenium Webdriver Cheat Sheet



Selenium Automation Testing, Selenium Architecture, Automation Testing, Selenium Interview questions with Answers, Selenium Error, Python, Selenium with TestNG, Page object Model, Devops, Manual Testing, Core java for selenium, Selenium 4 new update, Selenium 3, Selenium cheat sheet Git Hub Cheat Sheet. Preview 00:01.15. Selenium Webdriver-Techniques to automate Web elements 19 lectures. 2hr 49min. Handling Static.


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:

Macintosh website. 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:

Selenium Webdriver Downloads

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

Selenium webdriver api


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


Launch URL


Retrieve Browser Details:


Navigation


Locating Elements

By id

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


By Class Name

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


By Name

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


By Tag Name

<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” /> Torrent software for windows.

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()



Selenium Webdriver Cheat Sheet Example

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.


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.

Selenium Webdriver Cheat Sheet

Minimum modules to import


Created : 17 December 2019

Most complete selenium webdriver c# 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.

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.

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.

Selenium Webdriver Version

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.

Selenium Webdriver Tutorial

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.