Selenium Cheat Sheet

Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

Selenium Selenium Navigators Operations

CHEAT SHEET
• Navigate to url • Launch Webpage driver.get("www.webdriverinselenium.com");
driver.get(“http://newexample.com”) • Click Button driver.findElement(By.id("submit")).click();
driver.navigate().to(“http://newexample.com”) • Handle Alert Alert Alertpopup = driver.switchTo().alert();
• Refresh page • Disable a Field driver.getElementsByName(‘’)
driver.navigate().refresh()
Driver Initialization Basics • Navigate forwards in browser history
[0].setAttribute('disabled’,'');
• Enable a Field driver.getElementsByName(‘’)
driver.navigate().forward() [0].removeAttribute('disabled'; Screenshot.File
• Firefox WebDriver driver = new FirefoxDriver();
• Navigate backwards in browser history snapshot=((TakesScreenshot)driver)
• Chrome WebDriver driver = new ChromeDriver();
driver.navigate().back() .getScreenshotAs(OutputTypeFILE);
• Internet Explorer WebDriver driver = new SafariDriver();
• Safari Driver WebDriver driver = new InternetExplorerDriver(); FileUtils.copyFile(snapshot,
newFile("C:\\screenshot.jpg"));
TestNG • Print Title of Page String pagetitle = driver.getTitle();
System.out.print(pagetitle);
Driver Initialization Advanced • Implicit Wait driver.manage().timeouts().implicitlyWait(10,
@BeforeSuite @AfterSuite @BeforeTest @AfterTest @BeforeGroups @AfterGroups
@BeforeClass @AfterClass @BeforeMethod @AfterMethod TimeUnit.SECONDS); Explicit Wait
• Load Firefox from different location: WebDriverWait wait=new WebDriverWait(driver,
System.setProperty(“webdriver.firfox.bin”,“path/to/firfox/binary”); 20);
• Sleep Thread.Sleep(10);
FirefoxProfile fp= new FirefoxProfile(); JUNIT
• Load Firefox addons:
File file=new File(“path/to/extension.xpi”);
fp.addextension(file) @After @AfterClass @Before @BeforeClass @Ignore @Test Alerts
driver.switchTO().alert.getText();
Selenium Locators Windows driver.switchTO().alert.accept();
driver.switchTO().alert.dismiss();
String handle=driver.getWindowHandle(); driver.switchTO().alert.sendKeys(“Text”);
• Locating by ID Set<String> handles = getWindowHandles();
driver.findElement(By.id("q")).sendKeys("Se lenium 3"); driver.switchTo().window(handle);
• Locating by Name • How to switch to newly created window
driver.findElement(By.name("q")).sendKeys ("Selenium 3"); String curWindow=driver.getWindowHandle(); Selenium Grid
• Locating by Xpath • Get all window handles
driver.findElement(By.xpath("//input[@id='q']")).sendKeys("Selen Set<String> handles = getWindowHandles(); • Start hub: java-jar selenium-server- standalone-x.xx.x.jar-role hub
ium 3"); for(string handle: handles) • Start node: java-jar selenium-server- standalone-x.xx.x.jar-role node-hub
• Locating Hyperlinks by Link Text { • Server: http://localhost:4444/grid/console
driver.FindElement(By.LinkText("edit this page")).Click(); if (!handle.equals(curWindow))
• Locating by DOM {
dom =document.getElementById('signinForm') driver.switchTo().window(handle);
• Locating by CSS }
driver.FindElement(By.CssSelector("#rightb ar >.menu>li:nth-of-type(2)> }
h4"));
• Locating by ClassName
driver.findElement(By.className("profileheader")); Frames
• Locating by TagName
driver.findElement(By.tagName("select")).C lick();
• Locating by LinkText • Using Frame Index: driver.switchTO().frame(1);
driver.findElement(By.linkText("NextP age")).click(); • Using Name of Frame: driver.switchTo().frame(“name”)
• Locating by PartialLinkText • Using web Element Object: driver.switchTO().frame(element);
driver.findElement(By.partialLinkText(" NextP")).click(); • Get back to main document: driver.switchTO().defaultContent();
FURTHERMORE: Selenium Testing Training

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy