- Selenium Css Selector Cheat Sheet
- Css Selectors Selenium Cheat Sheet
- Selenium Css Selector Attribute
- Selenium Cheat Sheet Python
Selenium Cheat Sheet for Java. Download Selenium. Download selenium webdriver in this link. Dirty our hands! By CSS Selector.
- I was recently asked by a colleague for some advice on locators and I shared this cheat sheet with him. It contains just about everything you need to know for formulating locators for use with Selenium (and also Marionette), and includes syntax for both xpath and css selectors. I hope you find it as useful as I do. Selenium Locators Cheat Sheet.
- Consider using the Selenium DSL in a script driven test. Selenium provides support for Java, Python, Ruby, Groovy, PHP, and C#. Selenium IDE helps get a script-driven test started by exporting to a unit test format. For example, consider the following test in the Selenese table format: Use the Selenium IDE File menu, Export, Python Selenium RC.
- This cheat sheet has examples on common methods used in Selenium Automation. Suggestion is to learn Core Java before moving to Selenium Automation. If you already know Java then Selenium is peanut for you. Although Selenium supports various programming languages (C#, Java, Perl, PHP, Python & Ruby etc.) but this cheat sheet has exmples using.
For Python version the link is here
Selenium Css Selector Cheat Sheet
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.setProperty('webdriver.chrome.driver', “'Path To chromedriver');
To download: Visit Here
Firefox:
System.setProperty('webdriver.gecko.driver', 'Path To geckodriver');
To download: Visit GitHub
Internet Explorer:
System.setProperty('webdriver.ie.driver', 'Path To IEDriverServer.exe');
To download: Visit Here
Edge:
System.setProperty('webdriver.edge.driver', 'Path To MicrosoftWebDriver.exe');
To download: Visit Here
Opera:
System.setProperty('webdriver.opera.driver', 'Path 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:
Css Selectors Selenium Cheat Sheet
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” />
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 Css Selector Attribute
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.
Selenium Cheat Sheet Python
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.
Minimum modules to import
Created : 17 December 2019