[go: up one dir, main page]

0% found this document useful (0 votes)
2K views1 page

Selenium Cheat Sheet

Selenium navigators allow automating navigation operations in a web browser such as launching a webpage, clicking buttons, handling alerts, taking screenshots, and refreshing pages. Locators help find elements on a webpage using strategies like ID, name, XPath, class name and more. Selenium supports test automation using TestNG and JUnit frameworks. It can also distribute tests using a hub and node architecture in Selenium Grid. Operations with frames and windows like switching between them are possible. Implicit and explicit waits help synchronize test execution with page loads.

Uploaded by

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

Selenium Cheat Sheet

Selenium navigators allow automating navigation operations in a web browser such as launching a webpage, clicking buttons, handling alerts, taking screenshots, and refreshing pages. Locators help find elements on a webpage using strategies like ID, name, XPath, class name and more. Selenium supports test automation using TestNG and JUnit frameworks. It can also distribute tests using a hub and node architecture in Selenium Grid. Operations with frames and windows like switching between them are possible. Implicit and explicit waits help synchronize test execution with page loads.

Uploaded by

laxmanbethapudi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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