100% found this document useful (3 votes)
913 views

Selenium Cheatsheet

This document provides an overview of various actions and interactions that can be performed using Selenium WebDriver, including navigation, selecting elements, keyboard/mouse interactions, waiting, and touch actions. It summarizes the main capabilities of Selenium such as finding elements, performing actions on elements, waiting for elements to be in a certain state, cleaning data between tests, and using touch actions on mobile.

Uploaded by

dyskzg
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (3 votes)
913 views

Selenium Cheatsheet

This document provides an overview of various actions and interactions that can be performed using Selenium WebDriver, including navigation, selecting elements, keyboard/mouse interactions, waiting, and touch actions. It summarizes the main capabilities of Selenium such as finding elements, performing actions on elements, waiting for elements to be in a certain state, cleaning data between tests, and using touch actions on mobile.

Uploaded by

dyskzg
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Action combinations

Selenium WebDriver Actions action =


new Actions(driver);
Driver creation SelectElement var saveShortcut =
action.ContextClick(element)
new ChromeDriver(); var selectElement =
.KeyDown(Keys.Control)
new SelectElement(element);
.SendKeys("S")
Navigation .Build();
selectElement.SelectByText("2");
driver.Navigate().GoToUrl( selectElement.SelectByValue("2");
"https://translate.google.com"); MoveByOffset(offsetX, offset)
selectElement.SelectByIndex(2);
driver.Navigate().Refresh(); MoveToElement(toElement)
driver.Navigate().Back(); MoveToElement(toElement, offsetX,
driver.Navigate().Forward();
Properties offset)
driver.SwitchTo().Frame(element); element.Displayed ClickAndHold()
element.Enabled Release()
Selectors element.Selected ContextClick()
element.Text DoubleClick()
driver.FindElement(selector); element.Location KeyDown(key)
element.Size KeyUp(key)
By.Id("source") element.TagName SendKeys(keysToSend)
By.ClassName("city") element.GetAttribute(“name”) Click(onElement)
By.Name("email") ClickAndHold(onElement)
By.CssSelector("#cities") Release(onElement)
By.TagName("header")
Keyboard actions ContextClick(onElement)
By.XPath("//input") element.SendKeys("cat"); DoubleClick(onElement)
By.LinkText("Contact") element.SendKeys(Keys.Enter) DragAndDrop(source, target)
By.PartialLinkText("Contact") DragAndDropToOffset(source,
offsetX, offsetY)
Mouse actions KeyDown(element, key)
Select multiple elements
element.Click() KeyUp(element, key)
var elements = element.Submit() SendKeys(element, keysToSend)
driver.FindElements(selector)

Select nested element Using Java Script


var nestedElement = var element = (IWebElement) ((IJavaScriptExecutor)driver)
houseTile.FindElement(selector); .ExecuteScript("return $('.city')[0]");
Waiting Waiting for state
driver.Manage().Timeouts().SetScriptTimeout(TimeSpan.FromSeconds(10)); wait.Until(
driver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromSeconds(10)); ExpectedConditions

driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10)); .ElementToBeClickable(selector));

var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10)); ElementExists


ElementIsVisible
ElementSelectionStateToBe
Wait until element found ElementToBeClickable
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10)); ElementToBeSelected
IWebElement myDynamicElement = wait.Until<IWebElement>((d) => AlertIsPresent
{ AlertState
return d.FindElement(By.Id("someDynamicElement")); FrameToBeAvailableAndSwitchToIt
}); InvisibilityOfElementLocated
InvisibilityOfElementWithText
PresenceOfAllElementsLocatedBy
Cleaning VisibilityOfAllElementsLocatedBy
StalenessOf
driver.Manage().Cookies.DeleteAllCookies(); TextToBePresentInElement
new RemoteLocalStorage(driver).Clear(); TextToBePresentInElementLocated
new RemoteSessionStorage(driver).Clear(); TextToBePresentInElementValue
TitleContains
TitleIs
TouchActions UrlContains
var touchAction = new TouchActions(driver); UrlMatches
UrlToBe
touchAction
.SingleTap(element)
.DoubleTap(element)
.Scroll(offsetX, offsetY)
.Down(locationX, locationY) www.diwebsity.com
.Up(locationX, locationY) Web diversity in few simple words
.LongPress(element)
.Flick(element, offsetX, offsetY, speed) Blog about modern technology in web
.Build(); development and testing

You might also like