Selenium WebDriver Cheat Sheet
by Rajesh (rajeshcdp) via cheatography.com/33195/cs/10324/
Locators Browser Commands RadioButton
ID Get command isSelected not Selected
Name Get Title Command
Browser Navigation Commands
Link Text Get current Url Command
CSS Selector - Tag and ID, Tag and Class, Tag Get Page Source Command To Command Refresh Command
and Attribute, Tag ID Class and Attribute , Inner Back Command Forward Command
Close Command
Text
Quit Command
DOM - GetElementById, Switch Commands
Refresh Command
GetElementByName,dom:name,dom:index
driver.switchTo.window("WindowName")
XPATH
testNG Annotations driver.switchTo.frame("FrameName")
@Test @Before @AferM @BeforeCl driver.SwitchTo.alert()
Implicit Wait Vs Explicit Wait Vs Fluent Wait
Method ethod ass
This wait can be This wait can be CheckBox
@Before @AfterGr @Before @AfterTest
considered as element considered as
Group oup Test Checked not Checked
detection timeout. Once conditional wait,
defined in a script, this and is applied to a @Before @AfterSuite
wait will be set for all the particular Web Suite Difference between '/' and '//'
Web Elements on a Element with a
Single Slah '/' -> Look for the element
page. condition Web Element Commands
immediately inside its parent element
Selenium keeps polling WebDriverWait
Elements can be found by using Eg : Absolute path
to check whether that wait = new
By Id :/html/body/form/div/div[3]/[p1]/a
element is available to WebDriverWait(Dri
interact with or not. ver, 90); By Name Double Slah '//' -> Look for any child or grand
child inside parent element
Driver.manage().timeouts wait.until(Expected By Class Name
().implicitlyWait(90, Conditions.visibility eg: Releative path ://*[@id:loginform][p1]/a
By Tag Name
TimeUnit.SECONDS); OfElementsLocated
By Link Text
By(By.xpath("//input[‐ DropDown
@type='text']"))); By Partial Link Text
selectByVisibleText selectByIndex
Fluent Wait you have an element which By CSS
selectByValue
sometime appears in just 1 second and some By Xpath
time it takes minutes to appear. In that case it is
better to use fluent wait, as this will try to find findElement Vs findElements
element again and again until it find it or until
Returns a single Returns List of
the final timer runs out.
WebElement WebElements.
Syntax: Syntax:
WebElement java.util.List<WebElement
findElement(By > findElements(By by)
by)
Exception Exception:emptyListofWeb
:NoSuchElementE ElementObject
xception
By Rajesh (rajeshcdp) Published 26th December, 2016. Sponsored by CrosswordCheats.com
cheatography.com/rajeshcdp/ Last updated 26th December, 2016. Learn to solve cryptic crosswords!
Page 1 of 1. http://crosswordcheats.com