Selenium provides a variety of methods to perform actions on a browser. Some of those are described below:
1. get() :
It is used to load a new page in the current browser. This method blocks the WebDriver test execution until the page load is complete.
// Need to import following packages
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
//Instance of FirefoxDriver
WebDriver ffDriver = new FirefoxDriver();
//Open google.com site
ffDriver.get("http://www.google.com") ;
2. getCurrentUrl() :
It is used to get current url. Return type of this method is string.
//Instance of FirefoxDriver
WebDriver ffDriver = new FirefoxDriver();
//To get Current Url
String strCurrentUrl = ffDriver.getCurrentUrl() ;
3. getTitle() :
It returns the title of current web page. Return type of this method is string.
//Instance of FirefoxDriver
WebDriver ffDriver = new FirefoxDriver();
//To get Current Url
String strGetTitle = ffDriver.getTitle() ;
4. findElement() :
Finds matched element in the current page. If no matched element is found till
timeout time. then it returns an exception.
WebElement btnElement = driver.findElement(By.id("ButtonId"));
5. findElements():
Finds all the matched elements in the current page. If element does not found then it will return empty list.
List<WebElement> lstElement = driver.findElement(By.tagName("a"));
6. navigate() :
This method is used to back, forward, refresh and navigate.
i. driver.navigate().back()
ii. driver.navigate().forward()
iii. driver.navigate().refresh()
iv. driver.navigate().to("URL")
1. get() :
It is used to load a new page in the current browser. This method blocks the WebDriver test execution until the page load is complete.
// Need to import following packages
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
//Instance of FirefoxDriver
WebDriver ffDriver = new FirefoxDriver();
//Open google.com site
ffDriver.get("http://www.google.com") ;
2. getCurrentUrl() :
It is used to get current url. Return type of this method is string.
//Instance of FirefoxDriver
WebDriver ffDriver = new FirefoxDriver();
//To get Current Url
String strCurrentUrl = ffDriver.getCurrentUrl() ;
3. getTitle() :
It returns the title of current web page. Return type of this method is string.
//Instance of FirefoxDriver
WebDriver ffDriver = new FirefoxDriver();
//To get Current Url
String strGetTitle = ffDriver.getTitle() ;
4. findElement() :
Finds matched element in the current page. If no matched element is found till
timeout time. then it returns an exception.
WebElement btnElement = driver.findElement(By.id("ButtonId"));
5. findElements():
Finds all the matched elements in the current page. If element does not found then it will return empty list.
List<WebElement> lstElement = driver.findElement(By.tagName("a"));
6. navigate() :
This method is used to back, forward, refresh and navigate.
i. driver.navigate().back()
ii. driver.navigate().forward()
iii. driver.navigate().refresh()
iv. driver.navigate().to("URL")
No comments:
Post a Comment