You are on page 1of 4

Webdriver methods-

get(String )-

-To open given url

-manage()

driver.manage().window().maximize();
Thread.sleep(2000);
driver.manage().window().minimize();
Thread.sleep(2000);
driver.manage().window().maximize();

to verify the url-


getCurrentUrl();

package selenium;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Test1 {

public static void main(String[] args) throws InterruptedException {

System.setProperty("webdriver.chrome.driver","C:\\Users\\Admin\\
Desktop\\Slenium Jar\\Chrome_98\\chromedriver.exe");

WebDriver driver=new ChromeDriver();

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

driver.get("https://www.selenium.dev/downloads/");

String url=driver.getCurrentUrl();
System.out.println(url);
String expectedurl="https://www.google.dev/downloads/";

if (url.equals(expectedurl)) {

System.out.println("title matched-TC Pass");


}
else {
System.out.println("title doesn't macth -TC Fail");
}

Thread.sleep(8000);
driver.close();

to close the browser open -

driver.close();

navigate method-

driver.navigate().to("https://www.facebook.com/");
Thread.sleep(2000);
driver.navigate().back();
Thread.sleep(2000);
driver.navigate().forward();
Thread.sleep(2000);
driver.navigate().refresh();

get vs navigate methods-

1) type of available methods-

2) void vs Navigation

3) Wait until page loading vs doesnot wait until whole page loaded

Locators-

Locators are used to locate te web elemenent on the webpage.

Web Element- it is kind of object present on webpage.

to findout webElement on webpage we are using the findElement() & FindElements()


methods-
webdriver.

Selenium there are 8 types of locators-


This locators are present in By class of selenium.

Base on attribute
1) id

2) class

3) name

Bae on the tagname


4) tagname
<word

base on the text present

5)linkedText

6) partialLinked Text()

base on the expression

7) cssSelector

8) xpath

ex-

package selenium;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Test1 {

public static void main(String[] args) throws InterruptedException {

System.setProperty("webdriver.chrome.driver","C:\\Users\\Admin\\
Desktop\\Slenium Jar\\Chrome_98\\chromedriver.exe");

//Step=1
WebDriver driver=new ChromeDriver();

//Step=2
driver.manage().window().maximize();

//Step=3
driver.get("https://www.facebook.com/");

//step=4 Find out webElement on webpage


WebElement username=driver.findElement(By.name("email"));
username.sendKeys("abc@gmail.com");

//Step=5
WebElement password=driver.findElement(By.name("pass"));
password.sendKeys("pass12345");

//step=6
WebElement loginButton=driver.findElement(By.name("login"));
//loginButton.click();

WebElement creatAccButton=driver.findElement(By.linkText("Forgotten
password?"));

creatAccButton.click();
Thread.sleep(8000);
driver.close();

You might also like