Вы находитесь на странице: 1из 2

Selenium WebDriver Cheat Sheet Cheat Sheet

by Narayanan Palani (Narayanan Palani) via cheatography.com/32112/cs/9838/

Driver Initialization Selenium Locators (cont)

Firefox (Below v.47) Refer System.setProperty("webdriver.gecko.driv Locating by LinkTextRefer driver.findElement(By.linkText("NextP


Part2-Page58 er", "PathTo\\geckodriver.exe"); Part2-Page37-40 age")).click();

Download from WebDriver driver = new FirefoxDriver(); Locating by driver.findElement(By.partialLinkText("


https://github.com/mozilla/gecko PartialLinkTextRefer NextP")).click();
driver/releases Part2-Page37-40

Chrome Refer
Part2-Page59 System.setProperty("WebDriver.chrome.
driver", Selenium Exceptions
System.getProperty("user.dir")+"//Browse
'Server Exception : sessionId should not Replace Chrome Driver
rDrivers//chromedriver.exe");
be nullRefer Part2-Page160 with Latest Version
Download from WebDriver driver = new
https://sites.google.com/a/chrom ChromeDriver(); ERROR: No sessionId providedRefer Use Jenkins
Part2-Page160
ium.org/chromedriver/download
s UnreachableBrowserException Refer
Registry Key Changes
Internet ExplorerRefer System.setProperty("WebDriver.ie.driver" Part2-Page160 Recommended
Part2-Page59 , "PathTo//IEDriverServer.exe");
Illegal state exception using Selenium Get latest Firefox Gecko
Download from The Internet WebDriver driver = new 3Refer Part2-Page161 Driver
Explorer Driver Server at InternetExplorerDriver();
http://docs.seleniumhq.org/down Annotations
load/
TestNG @BeforeSuite @AfterSuite @BeforeTest @AfterTest
@BeforeGroups @AfterGroups @BeforeClass @AfterClass
Selenium Locators
@BeforeMethod @AfterMethod
Locating by ID Refer driver.findElement(By.id("q")).sendKeys("Se
JUnit @After @AfterClass @Before @BeforeClass @Ignore @Test
Part2-Page37 lenium 3");

Locating by NameRefer driver.findElement(By.name("q")).sendKeys Practice Scripts


Part2-Page37 ("Selenium 3");
Launch driver.get("www.webdriverinselenium.com");
Locating by XpathRefer driver.findElement(By.xpath("//input[@id='q'] WebpageRefer

Part2-Page37/38 ")).sendKeys("Selenium 3"); Part2-Page60

Locating Hyperlinks by driver.FindElement(By.LinkText("edit this Click driver.findElement(By.id("submit")).click();


Link Text Refer page")).Click();
Button Refer
Part2-Page38/39 Part2-Page60

Locating by DOMRefer dom Store TextRefer String txtDropdown =


Part2-Page39 =document.getElementById('signinForm') Part2-Page60 driver.findElement(By.ID("select")).getText();

Locating by CSSRefer driver.FindElement(By.CssSelector("#rightb Enter TextRefer driver.findElement(By.xpath("//input[@name='FirstNa


Part2-Page40-43 ar > .menu > li:nth-of-type(2) > h4")); Part2-Page61 me034']")).sendKeys("NarayananPalani");

Locating by driver.findElement(By.className("profile- Handle Alert Alertpopup = driver.switchTo().alert();


ClassNameRefer header"));
AlertRefer
Part2-Page37 Part2-Page62

Locating by driver.findElement(By.tagName("select")).C (Mouse)ClickRe driver.findElement(By.xpath("//input[@value='OBJECT


TagNameRefer
lick(); fer Part2-Page62 NAME']")).click();
Part2-Page37
Compare Assert.assertTrue(chkbox12.isSelected());
TextRefer
Part2-Page64

By Narayanan Palani Published 15th November, 2016. Sponsored by CrosswordCheats.com


(Narayanan Palani) Last updated 2nd August, 2017. Learn to solve cryptic crosswords!
cheatography.com/narayanan- Page 1 of 2. http://crosswordcheats.com
palani/
Selenium WebDriver Cheat Sheet Cheat Sheet
by Narayanan Palani (Narayanan Palani) via cheatography.com/32112/cs/9838/

Practice Scripts (cont)

Disable a driver.getElementsByName('<ObjectID>')
FieldRefer [0].setAttribute('disabled', '');
Part2-Page64

Enable a driver.getElementsByName('<ObjectID>')
FieldRefer [0].removeAttribute('disabled';
Part2-Page64

ScreenshotRefe File snapshot =


r Part2-Page64 ((TakesScreenshot)driver).getScreenshotAs(OutputType.
FILE);

FileUtils.copyFile(snapshot, new
File("C:\\screenshot.jpg"));

Print the Title of String pagetitle = driver.getTitle();


the PageRefer
Part2-Page68

System.out.print(pagetitle);

Implicit driver.manage().timeouts().implicitlyWait(10,
WaitRefer TimeUnit.SECONDS);
Part2-Page69

Explicit WebDriverWait wait = new WebDriverWait(driver, 20);


WaitRefer
Part2-Page70

wait.until(ExpectedConditions.textToBePresentInElement
Located(By.xpath("//div[@id='<Object ID>']"), "Enter
Your Personal Details"));

Fluent Wait wait = new FluentWait(driver)


WaitRefer
Part2-Page70

.withTimeout(20, SECONDS)

SleepRefer
Thread.Sleep(10);
Part2-Page70

By Narayanan Palani Published 15th November, 2016. Sponsored by CrosswordCheats.com


(Narayanan Palani) Last updated 2nd August, 2017. Learn to solve cryptic crosswords!
cheatography.com/narayanan- Page 2 of 2. http://crosswordcheats.com
palani/

Вам также может понравиться