Selenium WebDriver Methods
1) get() Method
It opens specified URL inwards the Browser window
Syntax:
driverObject.get("URL")
Example:
driver.get("http://www.google.com");
--------------------------------------------
2) getTitle() Method
It returns championship of the Browser
Syntax:
String stringName = driverObject.getTitle();
Example:
String Title = driver.getTitle();
System.out.println(Title);
--------------------------------------------
3) getPageSource()
It returns the page source
Syntax:
String stringName = driverObject.getPageSource();
Example:
String Pagesource = driver.getPageSource();
System.out.println(Pagesource);
--------------------------------------------
4) getCurrentUrl()
It returns electrical current url of the Browser
Syntax:
String stringName = driverObject.getCurrentUrl();
Example:
String CurrentUrl = driver.getCurrentUrl();
System.out.println(CurrentUrl);
--------------------------------------------
Browser Navigation Methods:
5) navigate().to() Method
Loads a novel spider web page inwards the electrical current browser window.
Synatx:
driverObject.navigate().to();
example:
driver.navigate().to("http://www.yahoo.com");
------------------------------------------
6) navigate().back();
It moves a unmarried special dorsum inwards the spider web browser's history
Syntax:
driverObject.navigate().back();
---------------------
Example:
driver.get("http://www.google.com");
driver.navigate().to("http://www.yahoo.com");
driver.navigate().back();
--------------------------------------------
7) navigate().forward()
It moves a unmarried special forwards inwards the Browser history
Syntax:
driverObject.navigate().forward();
Example:
driver.get("http://www.google.com");
driver.navigate().to("http://www.yahoo.com");
driver.navigate().back();
driver.navigate().forward();//yahoo
--------------------------------------------
8) naviagte().refresh()
It refreshes the electrical current spider web page
Syntax:
driverObject.navigate().refresh();
Example:
driver.get("http://www.google.com");
driver.navigate().refresh();
--------------------------------------------
9) close()
It closes the foused browser
Synatx:
driverObject.close();
Example:
driver.get("file:///E:/HTMLExamples/LoginPage.html");
driver.findElement(By.linkText("Sign In")).click();
driver.close();
--------------------------------------------
10) quit()
It closes all Browsers that opened past times WebDriver during execution.
Synatx:
driverObject.quit();
example:
driver.get("file:///E:/HTMLExamples/LoginPage.html");
driver.findElement(By.linkText("Sign In")).click();
driver.quit();
--------------------------------------------
11) findElement()
It finds start chemical component subdivision inside the electrical current page using the given locator as well as returns unmarried element.
Syntax:
WebElemnt objectname = driver.findElement(By.locator("locator value"));
objectname.method();
Or
driver.findElement(By.locator("locator value")).method();
Example:
WebElement e = driver.findElement(By.id("Email"));
e.sendKeys("abcd");
Or
driver.findElement(By.id("Email")).sendKeys("abcd");
--------------------------------------------
12) sendKeys()
Enters a Value inwards to Text box / Edit box
Syntax:
driverObject.findElement(By.lcator("locator value")).sendkeys("value");
Or
WebElement ObjectName = driverObject.findElement(By.lcator("locator value"))
ObjectName..sendkeys("value");
Example:
driver.findElement(By.id("Email")).sendKeys("abcd");
Or
WebElement e = driver.findElement(By.id("Email"));
e.sendKeys("abcd");
--------------------------------------------
13) clear()
It clears the value from a text box or edit box
Syntax:
driverObject.findElement(By.lcator("locator value")).clear();
Example:
driver.findElement(By.id("Email")).clear();
--------------------------------------------
14) click()
It clicks an element
Synatx:
driverObject.findElement(By.locator("locator value")).click();
Or
WebElement ObjectName = driverObject.findElement(By.locator("locator value"));
ObjectName.click;
Examples:
click method on Button Object
driver.get("http:/gmail.com");
driver.findElement(By.id("signIn")).click();
---------------------------
click method on Link Object
driver.get("http:/google.com");
driver.findElement(By.linkText("Gmail")).click();
--------------------------------------------
15) isEnabled()
It checks conditions the chemical component subdivision is inwards enabled solid soil or not?
Syntax:
boolean variableName = driverObject.findElement(By.locator("locator value")).isEnabled();
Example:
driver.get("http:/google.com");
boolean i = driver.findElement(By.linkText("Gmail")).isEnabled();
System.out.println(i);
--------------------------------------------
16) maximize()
Syntax:
driver().manage().window().maximize();
Example:
driver.get("http:/google.com");
driver.manage().window().maximize();
--------------------------------------------
17) isSelected()
It checks if the banking enterprise lucifer box or the Radio push clit is selected or not? as well as returns Boolean results.
Syntax:
boolean VariableName = driver.findElement(By.locator("locator value")).isSelected();
Example:
boolean a1 = driver.findElement(By.xpath("html/body/input[2]")).isSelected();
System.out.println(a1); //true
------------------------------------------
18) isDisplayed()
It checks if the chemical component subdivision is displayed or not?
Syntax:
boolean variableName = driver.findElement(By.locator("locator value")).isDisplayed();
Example:
boolean a = driver.findElement(By.xpath(".//*[@id='gbw']/div/div/div[1]/div[2]/a")).isDisplayed();
System.out.println(a);
--------------------------------
19) getText()
It returns text value that acquaint inwards the spider web page.
Syntax:
String StringName = driverObject.findElement(By.locator("locator value").getText();
Ex:
WebDriver driver = novel FirefoxDriver();
driver.get("http:/gmail.com");
String s = driver.findElement(By.xpath("html/body/div[1]/div[2]/div[1]/h1")).getText();
System.out.println(s);
driver.close();
--------------------------------------------
20) implicitlyWait()
Syntax:
driver.manage().timeouts().implicitlyWait(Time inwards seconds, TimeUnit.Seconds);
Example:
WebDriver driver = novel FirefoxDriver();
driver.get("http:/gmail.com");
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
String s = driver.findElement(By.xpath("html/body/div[1]/div[2]/div[1]/h1")).getText();
System.out.println(s);
driver.close();
---------------------------------------------
Sumber http://www.gcreddy.com/
1) get() Method
It opens specified URL inwards the Browser window
Syntax:
driverObject.get("URL")
Example:
driver.get("http://www.google.com");
--------------------------------------------
2) getTitle() Method
It returns championship of the Browser
Syntax:
String stringName = driverObject.getTitle();
Example:
String Title = driver.getTitle();
System.out.println(Title);
--------------------------------------------
3) getPageSource()
It returns the page source
Syntax:
String stringName = driverObject.getPageSource();
Example:
String Pagesource = driver.getPageSource();
System.out.println(Pagesource);
--------------------------------------------
4) getCurrentUrl()
It returns electrical current url of the Browser
Syntax:
String stringName = driverObject.getCurrentUrl();
Example:
String CurrentUrl = driver.getCurrentUrl();
System.out.println(CurrentUrl);
--------------------------------------------
Browser Navigation Methods:
5) navigate().to() Method
Loads a novel spider web page inwards the electrical current browser window.
Synatx:
driverObject.navigate().to();
example:
driver.navigate().to("http://www.yahoo.com");
------------------------------------------
6) navigate().back();
It moves a unmarried special dorsum inwards the spider web browser's history
Syntax:
driverObject.navigate().back();
---------------------
Example:
driver.get("http://www.google.com");
driver.navigate().to("http://www.yahoo.com");
driver.navigate().back();
--------------------------------------------
7) navigate().forward()
It moves a unmarried special forwards inwards the Browser history
Syntax:
driverObject.navigate().forward();
Example:
driver.get("http://www.google.com");
driver.navigate().to("http://www.yahoo.com");
driver.navigate().back();
driver.navigate().forward();//yahoo
--------------------------------------------
8) naviagte().refresh()
It refreshes the electrical current spider web page
Syntax:
driverObject.navigate().refresh();
Example:
driver.get("http://www.google.com");
driver.navigate().refresh();
--------------------------------------------
9) close()
It closes the foused browser
Synatx:
driverObject.close();
Example:
driver.get("file:///E:/HTMLExamples/LoginPage.html");
driver.findElement(By.linkText("Sign In")).click();
driver.close();
--------------------------------------------
10) quit()
It closes all Browsers that opened past times WebDriver during execution.
Synatx:
driverObject.quit();
example:
driver.get("file:///E:/HTMLExamples/LoginPage.html");
driver.findElement(By.linkText("Sign In")).click();
driver.quit();
--------------------------------------------
11) findElement()
It finds start chemical component subdivision inside the electrical current page using the given locator as well as returns unmarried element.
Syntax:
WebElemnt objectname = driver.findElement(By.locator("locator value"));
objectname.method();
Or
driver.findElement(By.locator("locator value")).method();
Example:
WebElement e = driver.findElement(By.id("Email"));
e.sendKeys("abcd");
Or
driver.findElement(By.id("Email")).sendKeys("abcd");
--------------------------------------------
12) sendKeys()
Enters a Value inwards to Text box / Edit box
Syntax:
driverObject.findElement(By.lcator("locator value")).sendkeys("value");
Or
WebElement ObjectName = driverObject.findElement(By.lcator("locator value"))
ObjectName..sendkeys("value");
Example:
driver.findElement(By.id("Email")).sendKeys("abcd");
Or
WebElement e = driver.findElement(By.id("Email"));
e.sendKeys("abcd");
--------------------------------------------
13) clear()
It clears the value from a text box or edit box
Syntax:
driverObject.findElement(By.lcator("locator value")).clear();
Example:
driver.findElement(By.id("Email")).clear();
--------------------------------------------
14) click()
It clicks an element
Synatx:
driverObject.findElement(By.locator("locator value")).click();
Or
WebElement ObjectName = driverObject.findElement(By.locator("locator value"));
ObjectName.click;
Examples:
click method on Button Object
driver.get("http:/gmail.com");
driver.findElement(By.id("signIn")).click();
---------------------------
click method on Link Object
driver.get("http:/google.com");
driver.findElement(By.linkText("Gmail")).click();
--------------------------------------------
15) isEnabled()
It checks conditions the chemical component subdivision is inwards enabled solid soil or not?
Syntax:
boolean variableName = driverObject.findElement(By.locator("locator value")).isEnabled();
Example:
driver.get("http:/google.com");
boolean i = driver.findElement(By.linkText("Gmail")).isEnabled();
System.out.println(i);
--------------------------------------------
16) maximize()
Syntax:
driver().manage().window().maximize();
Example:
driver.get("http:/google.com");
driver.manage().window().maximize();
--------------------------------------------
17) isSelected()
It checks if the banking enterprise lucifer box or the Radio push clit is selected or not? as well as returns Boolean results.
Syntax:
boolean VariableName = driver.findElement(By.locator("locator value")).isSelected();
Example:
boolean a1 = driver.findElement(By.xpath("html/body/input[2]")).isSelected();
System.out.println(a1); //true
------------------------------------------
18) isDisplayed()
It checks if the chemical component subdivision is displayed or not?
Syntax:
boolean variableName = driver.findElement(By.locator("locator value")).isDisplayed();
Example:
boolean a = driver.findElement(By.xpath(".//*[@id='gbw']/div/div/div[1]/div[2]/a")).isDisplayed();
System.out.println(a);
--------------------------------
19) getText()
It returns text value that acquaint inwards the spider web page.
Syntax:
String StringName = driverObject.findElement(By.locator("locator value").getText();
Ex:
WebDriver driver = novel FirefoxDriver();
driver.get("http:/gmail.com");
String s = driver.findElement(By.xpath("html/body/div[1]/div[2]/div[1]/h1")).getText();
System.out.println(s);
driver.close();
--------------------------------------------
20) implicitlyWait()
Syntax:
driver.manage().timeouts().implicitlyWait(Time inwards seconds, TimeUnit.Seconds);
Example:
WebDriver driver = novel FirefoxDriver();
driver.get("http:/gmail.com");
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
String s = driver.findElement(By.xpath("html/body/div[1]/div[2]/div[1]/h1")).getText();
System.out.println(s);
driver.close();
---------------------------------------------