[go: up one dir, main page]

0% found this document useful (0 votes)
133 views6 pages

Selenium Cheat Sheet

Driver Initialization Basics provides an overview of initializing web drivers for different browsers like Firefox, Chrome, Internet Explorer, and Safari. It also covers loading Firefox from a different location and adding extensions. Operations describes various browser automation tasks like launching webpages, interacting with elements, taking screenshots, handling alerts and popups. Locators and Navigators define techniques for finding page elements and controlling browser navigation. Frames, Windows, Cookies and JavaScript dialogs are also addressed. JUnit and TestNG annotations are explained for structuring automated tests.

Uploaded by

sejal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as XLSX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
133 views6 pages

Selenium Cheat Sheet

Driver Initialization Basics provides an overview of initializing web drivers for different browsers like Firefox, Chrome, Internet Explorer, and Safari. It also covers loading Firefox from a different location and adding extensions. Operations describes various browser automation tasks like launching webpages, interacting with elements, taking screenshots, handling alerts and popups. Locators and Navigators define techniques for finding page elements and controlling browser navigation. Frames, Windows, Cookies and JavaScript dialogs are also addressed. JUnit and TestNG annotations are explained for structuring automated tests.

Uploaded by

sejal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as XLSX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Purpose Function

Driver Initialization Basics:

Driver Initialization Advanced: A. Load firefox from different location:


B. Load firfox addons

Operations: Launch Webpage:


Click Button/Image/Link
Disable a Field:
Enable a Field :
Screenshot :
Print the Title of the Page:
input some text

send keyboard actions, press `ctral+a` & `backspace`

visibility
Get text
Get attribue
Get the select element
Get all the options for this element
Delete cookies By name
Delete All cookie
Java Script Dialouge handle javascript dialog
Select the options
Checkbox/Radio Check if it is selected
Select the element
Deselect the element
Wait/Sleep Implicit Wait:
Explicit Wait:
Sleep :
wait for a specific element to show up
wait 10 seconds until the element appear

Locators: Locating by ID
Locating by Name
Locating by Xpath
Locating Hyperlinksby Link Text
Locating by DOM
Locating by CSS
Locating by ClassName
Locating by TagName
Locating by LinkText
Locating by PartialLinkText

Navigators: Navigate to url


Refresh page
Navigate forwards in browser history
Navigate backwards in browser history

Windows Handle switch to newly created window


Get all window handles

Frames Using Frame Index:


Using Name of Frame:
Using web Element Object:
Get back to main document:

Alerts: Capture the alert message:


Click on the ‘OK’ button of the alert:
Click on the ‘Cancel’ button of the alert:
Send some data to alert box:

JUNIT annotations: @Test: test method to run with public void return type
@After: method to run after test method
@AfterClass: method to run before test method
@Before: method to run before test method
@BeforeClass: method to run once before any of the test methods in the class have b
@Ignore: This annotation is used to ignore a method

TestNG annotations: @test: This annotation marks a class or method as a part of a test
@BeforeSuite: This annotation makes sure that the method only run once before all t
@AfterSuite: This annotation makes sure that the method runs once after the executio
@BeforeTest: This annotation will make sure that the method marked with this anno
@AfterTest: This annotation will make sure that the method marked with this annota
@BeforeGroups : A method annotated with this annotation will run before all the firs
@AfterGroups: A method annotated with this annotation will run after all the test me
@BeforeClass: A method annotated with this annotation will run only once per class
@AfterClass: A method annotated with this annotation will run only once per class a
@BeforeMethod: A method annotated with this annotation will run before every @te
@AfterMethod: A method annotated with this annotation will run after every @test a
Command
Firefox WebDriver driver = new FirefoxDriver();
Chrome WebDriver driver = new ChromeDriver();
Safari Driver WebDriver driver = new InternetExplorerDriver();
Internet Explorer WebDriver driver = new SafariDriver();

System.setProperty(“webdriver.firfox.bin”,“path/to/firfox/binary”); FirefoxProfilefp= new FirefoxProfile();


File file=new File(“path/to/extension.xpi”); fp.addextension(file)

get("www.webdriverinselenium.com");
findElement(By.id("submit")).click();
getElementsByName('') [0].setAttribute('disabled', '')
getElementsByName('') [0].removeAttribute('disabled');
File snapshot = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); FileUtils.copyFile(snapshot, new File("C:\\scre
String pagetitle = driver.getTitle(); System.out.print(pagetitle);
driver.find_element(:id, 'TextArea').send_keys 'InputText'

driver.find_element(:id, 'TextArea').send_keys [:contol, 'a'], :backspace

driver.find_element(:id,'Element').displayed?
driver.find_element(:id,'Element').text
driver.find_element(:id, 'Element').attribute('class')
select = driver.find_element(:tag_name, "select")
all_options = select.find_elements(:tag_name, "option")
driver.manage.delete_cookie("CookieName")
driver.manage.delete_all_cookies
a.dismiss
puts
else "Value is: " + option.attribute("value")
option.click
end
driver.find_element(:id, 'CheckBox').selected?
driver.find_element(:id, 'CheckBox').click
driver.find_element(:id, 'CheckBox').clear
manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
WebDriverWait wait = new WebDriverWait(driver, 20);
Thread.Sleep(10);
wait = Selenium::WebDriver::Wait.new(:timeout => 10) (set the timeout to 10 seconds)
wait.until { driver.find_element(:id => "foo") }

driver.findElement(By.id("q")).sendKeys("Se lenium 3");


driver.findElement(By.name("q")).sendKeys ("Selenium 3");
driver.findElement(By.xpath("//input[@id='q'])).sendKeys("Selenium 3");
driver.FindElement(By.LinkText("edit this page")).Click();
dom =document.getElementById('signinForm')
driver.FindElement(By.CssSelector("#rightbar> .menu >li:nth-of-type(2) > h4"));
driver.findElement(By.className("profileheader"));
driver.findElement(By.tagName("select")).C lick();
driver.findElement(By.linkText("NextP age")).click();
driver.findElement(By.partialLinkText(" NextP")).click();

driver.get(“http://newexample.com”); driver.navigate().to(“http://newexample.com”)
driver.navigate().refresh()
driver.navigate().forward()
driver.navigate().back()

String curWindow=driver.getWindowHandle();
Set<String> handles = getWindowHandles(); For(string handle: handles) {If (!handle.equals(curWindow)) {driver.switchTo().w
}
}
driver.switchTO().frame(1);
driver.switchTo().frame(“name”)
driver.switchTO().frame(element);
driver.switchTO().defaultContent();

driver.switchTO().alert.getText();
driver.switchTO().alert.accept();
driver.switchTO().alert.dismiss();
driver.switchTO().alert.sendKeys(“Text”)

hods in the class have been executed

nly run once before all the tests have run


s once after the execution of all the tests
marked with this annotation runs before the first method annotated with @test
marked with this annotation runs after all the methods annotated with @test execute all the classes inside <test> tag in the testng.xml file.
ill run before all the first test methods run in that specific group
run after all the test methods run in that specific group
run only once per class and before all the first test methods run
un only once per class and after all the test methods run
ill run before every @test annotated method
l run after every @test annotated method
File("C:\\screenshot.jpg"));
switchTo().window(handle);

You might also like