Purpose Function Command
Driver Initialization Basics: Firefox WebDriver driver = new FirefoxDriver();
Chrome WebDriver driver = new ChromeDriver();
Safari Driver WebDriver driver = new InternetExplorerDriver();
Internet Explorer WebDriver driver = new SafariDriver();
Driver Initialization [Link](“[Link]”,“path/to/firfox/
A. Load firefox from different location:
Advanced: binary”); FirefoxProfilefp= new FirefoxProfile();
File file=new File(“path/to/[Link]”);
B. Load firfox addons
[Link](file)
Operations: Launch Webpage: get("[Link]");
Click Button/Image/Link findElement([Link]("submit")).click();
Disable a Field: getElementsByName('') [0].setAttribute('disabled', '')
Enable a Field : getElementsByName('') [0].removeAttribute('disabled');
File snapshot =
Screenshot : ((TakesScreenshot)driver).getScreenshotAs([Link]);
[Link](snapshot, new File("C:\\[Link]"));
Print the Title of the Page: String pagetitle = [Link](); [Link](pagetitle);
input some text driver.find_element(:id, 'TextArea').send_keys 'InputText'
send keyboard actions, press `ctral+a` & driver.find_element(:id, 'TextArea').send_keys [:contol,
`backspace` 'a'], :backspace
visibility driver.find_element(:id,'Element').displayed?
Get text driver.find_element(:id,'Element').text
Get attribue driver.find_element(:id, 'Element').attribute('class')
Get the select element select = driver.find_element(:tag_name, "select")
Get all the options for this element all_options = select.find_elements(:tag_name, "option")
Delete cookies By name [Link].delete_cookie("CookieName")
Delete All cookie [Link].delete_all_cookies
# get the alert : a = driver.switch_to.alert
# operation on the alert: if [Link] == 'A value you are looking
for'
Java Script Dialouge handle javascript dialog [Link]
else
[Link]
end
all_options.each do |option|
puts "Value is: " + [Link]("value")
Select the options [Link]
end
Checkbox/Radio Check if it is selected driver.find_element(:id, 'CheckBox').selected?
Select the element driver.find_element(:id, 'CheckBox').click
Deselect the element driver.find_element(:id, 'CheckBox').clear
Wait/Sleep Implicit Wait: manage().timeouts().implicitlyWait(10, [Link]);
Explicit Wait: WebDriverWait wait = new WebDriverWait(driver, 20);
Sleep : [Link](10);
wait = Selenium::WebDriver::[Link](:timeout => 10) (set
wait for a specific element to show up
the timeout to 10 seconds)
wait 10 seconds until the element appear [Link] { driver.find_element(:id => "foo") }
Locators: Locating by ID [Link]([Link]("q")).sendKeys("Se lenium 3");
Locating by Name [Link]([Link]("q")).sendKeys ("Selenium 3");
[Link]([Link]("//
Locating by Xpath
input[@id='q'])).sendKeys("Selenium 3");
Locating Hyperlinksby Link Text [Link]([Link]("edit this page")).Click();
Locating by DOM dom =[Link]('signinForm')
[Link]([Link]("#rightbar> .menu >li:nth-
Locating by CSS
of-type(2) > h4"));
Locating by ClassName [Link]([Link]("profileheader"));
Locating by TagName [Link]([Link]("select")).C lick();
Locating by LinkText [Link]([Link]("NextP age")).click();
Locating by PartialLinkText [Link]([Link](" NextP")).click();
[Link](“[Link]
Navigators: Navigate to url
[Link]().to(“[Link]
Refresh page [Link]().refresh()
Navigate forwards in browser history [Link]().forward()
Navigate backwards in browser history [Link]().back()
Windows Handle switch to newly created window String curWindow=[Link]();
Set<String> handles = getWindowHandles(); For(string
handle: handles) {If ()
Get all window handles {[Link]().window(handle);
}
}
Frames Using Frame Index: [Link]().frame(1);
Using Name of Frame: [Link]().frame(“name”)
Using web Element Object: [Link]().frame(element);
Get back to main document: [Link]().defaultContent();
Alerts: Capture the alert message: [Link]().[Link]();
Click on the ‘OK’ button of the alert: [Link]().[Link]();
Click on the ‘Cancel’ button of the alert: [Link]().[Link]();
Send some data to alert box: [Link]().[Link](“Text”)
@Test: test method to run with public void
JUNIT annotations:
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
been executed
@Ignore: This annotation is used to ignore
a method
@test: This annotation marks a class or
TestNG annotations:
method as a part of a test
@BeforeSuite: This annotation makes sure
that the method only run once before all
the tests have run
@AfterSuite: This annotation makes sure
that the method runs once after the
execution of all the tests
@BeforeTest: This annotation will make
sure that the method marked with this
annotation runs before the first method
annotated with @test
@AfterTest: This annotation will make sure
that the method marked with this
annotation runs after all the methods
annotated with @test execute all the
classes inside <test> tag in the
[Link] file.
@BeforeGroups : A method annotated with
this annotation will run before all the first
test methods run in that specific group
@AfterGroups: A method annotated with
this annotation will run after all the test
methods run in that specific group
@BeforeClass: A method annotated with
this annotation will run only once per class
and before all the first test methods run
@AfterClass: A method annotated with
this annotation will run only once per class
and after all the test methods run
@BeforeMethod: A method annotated with
this annotation will run before every @test
annotated method
@AfterMethod: A method annotated with
this annotation will run after every @test
annotated method