0% found this document useful (0 votes)
26 views

Selenium - Java Cheat Sheet

Selenium

Uploaded by

Pankaj Jha
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)
26 views

Selenium - Java Cheat Sheet

Selenium

Uploaded by

Pankaj Jha
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/ 9

01/09

Selenium - Java
Cheat Sheet

alphabin.co
02/09

Locating Elements - By
id:
driver.findElement(By.id("idValue"));

name:
driver.findElement(By.name("nameValue"));

cssSelector:
driver.findElement(By.cssSelector("input[ty
pe='submit]”));

XPath:
driver.findElement(By.xpath("//input[@typ
e='submit']"));

alphabin.co
03/09

tagName:
driver.findElement(By.tagName ("html
tagName"));

className:
driver.findElement(By.className
("classValue"));

linkText:
driver.findElement(By.linkText ("Sale"));

partialLinkText:
driver.findElement(By.partialLinkText
("link text"));

alphabin.co
04/09

Selenium Navigators
Navigate to URL:
driver.get(“https://alphabin.co/”);
OR
driver.navigate.to(“https://alphabin.co/”);

Refresh Page:
driver.navigate().refresh();

Navigate forward in browser:


driver.navigate().forward();

Navigate back in browser:


driver.navigate().back();

alphabin.co
05/09

Alerts
Accept an alert:
driver.switchTo().alert().accept();

Dismiss an alert:
driver.switchTo().alert().dismiss();

Enter text in an alert box:


driver.switchTo().alert().sendKeys("Alphabin");

Retrieve alert text:


driver.switchTo().alert().getText();

alphabin.co
06/09

iFrame
by index: → index start from 0
driver.switchTo().frame(0);

id/name:
driver.switchTo().frame("id or name of the
iFrame");

web element (locators):


WebElement middleFrame =
driver.findElement(By.xpath("//frame[@name=
'left']"));
driver.switchTo().frame(middleFrame);

alphabin.co
07/09

Actions
Step 1: Create the action object:
Actions actions=new Actions(driver);

Step 2: Locate the WebElement you want


to work on:
driver.switchTo().frame("id or name of the
iFrame");

alphabin.co
08/09

Step 3: Perform the action on the


WebElement
Right click:
actions.contextClick(element).perform();
Hover over:
actions.moveToElement(element).perform();
Double Click:
actions.doubleClick(element).perform();
Mouse Hover:
actions.moveToElement(element).build().perf
orm();

alphabin.co
09/09

Was This
Helpful

alphabin.co

You might also like