Classes and Methods Flashcards

1
Q

Pass URL to browser

A

driver.get(“ur”);
driver.navigate().to(“url”);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Get the current url from webpage

A

driver.getCurrentUrl();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Get the Page source

A

driver.getPageSource();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

navigate page back and forward

A

driver.navigate().back();
driver.navigate().forward();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Close the current tab and All Tabs

A

driver.close();
driver.quit();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Maximize window

A

driver.manage().window().maximize();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Page Load

A

driver.manage().timeouts().pageLoadTimeout( 10, TimeUnit.SECONDS);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Implicit Wait

A

driver.manage().timeouts().implicitlyWait( 10, TimeUnit.SECONDS);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Pass text/String/data and use keyboard

A

WebElement.sendKeys(“text here”);

WebElement.sendKeys(Keys.ARROW_DOWN);
WebElement.sendKeys(Keys.DOWN);

WebElement.sendKeys(Keys.ARROW_UP);
WebElement.sendKeys(Keys.UP);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Clear data

A

WebElement.clear();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Get the data/Text

A

WebElement.getText();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Click on webElement

A

WebElement.click();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Refresh webpage

A

driver.navigate().refresh();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Delete All cookies or specific cookies

A

driver.manage().deleteAllCookies();
driver.manage().deleteCookieNamed(“name specific here”);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Actions class syntax

A

Actions act = new Actions(driver);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Hover to element

A

Using Actions class.

Actions act = new Actions(driver);
act.moveToElement(WebElement).build().perform();

17
Q

Achieve multiple tasks in 1 line

A

Using Actions classes we can build it together

Actions act = new Actions(driver); act.moveToElement(elem).sendKeys(“data”).click().build().perform();

18
Q

Drag and drop web element

A

Using Actions class
Actions act = new Actions(driver);
act.dragAndDrop( sourceElement, DestinationElement).build().perform();

19
Q

Web Element attribute

A

String value = webElement.getAttribute(“attribute key”);

20
Q

Handle Java alerts

A

Using Alert Class.

driver.switchTo().alert();

21
Q

Java alert methods

A

driver.switchTo().alert().accept();
driver.switchTo().alert().dismiss();
driver.switchTo().alert().getText(); driver.switchTo().alert().sendKeys(“Some Data to sent”);

22
Q

Handle dropdown and it’s methods

A

Using Select class.
Select sel = new Select(WebElement)

sel.selectByValue(“Actual value here”);
sel.selectByIndex(2);
sel.selectByVisibleText(“HTML body”);

sel.getFirstSelectedOption();
sel.getAllSelectedOptions();
sel.deselectAll();
sel.isMultiple();

23
Q

All locators

A

driver.findElement(By.id(“IdHere”));
driver.findElement(By.className(“classNameHere”));
driver.findElement(By.xpath(“xPathHere”));
driver.findElement(By.cssSelector(“Css selector”));
driver.findElement(By.name(“nameHere”));
driver.findElement(By.tagName(“tagNameHere”)); driver.findElement(By.linkText(“LinkTextHere”)); driver.findElement(By.partialLinkText(“Partial text Here”));

24
Q

Locate an element using specific Text

A

//*[text()=’Français’] //’Français’ is text here.

25
Q

Locate element using partial text.

A

//*[contains(text(),’çais’)] //’çais’ is partial text

26
Q

Static Wait

A

Thread.sleep(1000); // 1 Second.

27
Q

Explicit Wait and it’s methods

A

WebDriverWait wait = new WebDriverWait(driver, 20);

//Methods:
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(“elem”)));

28
Q

Fluent Wait and it’s methods

A

Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
.withTimeout(10, TimeUnit.SECONDS )
.pollingEvery(5, TimeUnit.SECONDS )
.withMessage("User Defined: Timed out after 10 Seconds")
.ignoring(NoSuchElementException.class);</WebDriver></WebDriver>

    wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//path here")));
29
Q

Assertions and it’s methods

A

Assert.assertEquals(1,90); //Fails
Assert.assertNotEquals(1,2); //Pass
Assert.assertTrue(false); //Fail
Assert.assertFalse(false); //Pass
Assert.assertNull(null); //Pass
Assert.assertNotNull(null); //Fail
Assert.assertEquals(1, “Data” );
Assert.fail(“Custom Message”);

30
Q

SoftAssert

A

SoftAssert softAssert = new SoftAssert();

//Methods:
softAssert.assertEquals(1, 90); // Fails
softAssert.assertNotEquals(1, 2); // Pass
softAssert.assertTrue(false); // Fail
softAssert.assertFalse(false); // Pass
softAssert.assertNull(null); // Pass
softAssert.assertNotNull(null); // Fail
softAssert.assertEquals(1, “Data”);
softAssert.fail(“Custom Message”);
softAssert.assertAll();

31
Q

Validate Links using http……

A

URL url = new URL(“href link here….”);

HttpURLConnection huc = (HttpURLConnection) url.openConnection();
huc.connect();

String response = huc.getResponseMessage();
int responseCode = huc.getResponseCode();
huc.disconnect();

32
Q

Handle HTTPS certifications ( SSL )

A

ChromeOptions opt = new ChromeOptions();
opt.setAcceptInsecureCerts(true); //’Cert’ is for certificates.
WebDriver driver = new ChromeDriver(opt);

33
Q

Take Screenshot of webpage

A

File src = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtil.copyFile(src , new File(“new location here.png”));