Professional Documents
Culture Documents
FOR SELENIUM C#
CONTENTS
Browser Navigation 2
Web Page Operations 2
Driver Initialization 2
Windows Operations 3
Element Localization 3
Element Operations 4
Frames4
Alerts4
Waits4
Actions5
Cookies5
Screenshots5
BROWSER NAVIGATION
// Open page URL
driver.Navigate().GoToUrl("https://www.ultimateqa.com/");
// Navigation history
driver.Navigate().Forward();
driver.Navigate().Back();
driver.Navigate().Refresh();
SCREENSHOTS
ACTIONS // Take a screenshot of an element
var elementScreenshot = (webElement as
// Key down - keep a key pressed
ITakesScreenshot).GetScreenshot();
Actions actionProvider = new Actions(driver);
elementScreenshot.SaveAsFile("screenshot_
IAction keydown = actionProvider.
of_element.png");
KeyDown(Keys.Control).SendKeys("a").Build();
// Take a full-screen screenshot
keydown.Perform();
Screenshot screenshot = ((ITakesScreenshot)
// Key up - release pressed key
driver).GetScreenshot();
Actions actionProvider = new Actions(driver);
screenshot.SaveAsFile(@"file Path",
action.KeyDown(Keys.Shift).SendKeys(search,
ImageFormat.Png);
"qwerty").KeyUp(Keys.Shift).
SendKeys("qwerty").Perform();
// Drag and drop an element
IWebElement element = driver.
FindElement(By.Id("MyElement"));
Actions move = new Actions(driver);
move.DragAndDropToOffset(element, 30,
0).Perform();
// Upload a file
IWebElement element = driver.
FindElement(By.Id("UploadFile"));
element.SendKeys(filePath);