Different WebDriver Methods

mujeres solteras en celaya gto WebDriver Methods

  • get()
  • getTitle()
  • getPageSource()
  • getWindowHandles()
  • getWindowHandle()
  • getCurrentUrl()
  • findElement(By arg0)
  • findElements(By arg0)
  • manage()
  • navigate()
  • close()
  • quit()
  • switchTo()
  • Difference between close( ) and quit( ) methods

http://www.caibari.it/?freymyt=site-rencontre-femme-ukraine&62c=47 WebDriver Methods:

As WebDriver is an interface we need to recall the Java concept of interface. In interface all methods are abstract and it needs to be implemented in child classes (i.e. FirefoxDriver, ChromeDriver etc.). So below are the abstract methods of WebDriver, which are implemented in child class and became concrete. Each webdriver method is implemented to perform certain operations.

visit the site WebDriver Method : get(String ar0)

WebDriver get method is useful in navigate to particular web page in the current window browser and it will get the web page with the help of HTTP protocol.

Syntax: driver.get(String arg0)

Example:

public class Test {
public static void main(String[] args)
{
WebDriver driver = new FirefoxDriver();
driver.get("http://www.testingbar.com");
}
}

  coquetear a una mujer WebDriver Method : getTitle()

GetTitle selenium method is useful in capture or get the webpages page titles to assert whether particular webpage is loaded correctly or not in your test scripts.

Syntax : driver.getTitle();

Example:

public class Test {
public static void main(String[] args)
{
WebDriver driver = new FirefoxDriver();
driver.get("http://www. testingbar.com");
String Pagetitle =driver.getTitle();
System.out.println(Pagetitle);
}
}

click this over here now WebDriver Method: getPageSource()

getPageSource() is very much helpful if you want to validate anything(page title, attributes of element etc.) directly from html source code.

Syntax : driver.getPageSource();

Example:

public class Test{
public static void main(String[] args)
{
WebDriver driver = new FirefoxDriver();
driver.get("http://www. testingbar.com");
String page_source = driver.getPageSource();
System.out.println(page_source);
}
}

see this website WebDriver Method: getWindowHandle()

Whenever the web driver launches the browser it assigns the unique id to that browser which is called as window handler. This can be captured through this method.

Syntax : driver.getWindowHandle();

returnType: String

Example:

String windowId = driver.getWindowHandle();

https://www.cedarforestloghomes.com/enupikos/5742 WebDriver Method : getWindowHandles()

Whenever multiple windows are opened by webdriver and we want to capture all their ids. As all IDs are unique, we use return type, Set of string to keep all window ids.

Syntax: driver.getWindowHandles();

ReturnType: Set<String>

Example:

String current = driver.getWindowHandle();
for (String handle : driver.getWindowHandles()) {
   driver.switchTo().window(handle);
   if (title.equals(driver.getTitle())) {
     return;
   }
}
driver.switchTo().window(current);

http://meliggoi.gr/mokryxa/4416 WebDriver Method: getCurrentUrl()

getCurrentUrl() method will return current open window browser current URL in any browser like Firefox , Chrome or IE browsers.

Syntax : driver.getCurrentUrl()

Example:

public class Test {
public static void main(String[] args)
{
WebDriver driver = new FirefoxDriver();
driver.get("http://www. testingbar.com");
String url_current = driver.getCurrentUrl();
System.out.println("Current open url is -"+url_current);
}
}

rencontre gratuit au senegal WebDriver Method : findElement(By arg0)

It is used to find the first WebElement using the given method. Parameter is By which is a identifying elements like key. If it doesn’t find the element then it throws pop over to this site NoSuchElementFoundException.

Syntax : driver.findElement(By arg0)

Example:

//to launch the browser
driver.get(“http://www.facebook.com”);

//to findelements
WebElement we = driver.findElement(By.id(“button”));
we.click();

WebDriver Method : findElements()

It is used to find all elements which match locator value provided within the current page. If it doesn’t find the element then it won’t throw exception rather return a list of size zero.

Syntax: driver.findElements(By arg0)

Example:

//to launch the browser
driver.get(“http://www.facebook.com”);

//to findelements
List links=driver.findElements(By.TagName(“a”));

//Counting no of links in result page
System.out.println(links.size());

WebDriver Method : Manage()

This webdriver method is useful in performing different options like delete cookies, ImplicitWait, Maximize the windows

Example:

driver.manage().window().maximize();
// it works on current opened browser to maximize browser, resize browser, SetPosition etc.

driver.manage().deleteAllCookies();
// it deletes all cookies of current browser.

driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
// it implicitly waits for certain given time to look for the webelement before throwing timeout exception.

WebDriver Method : navigate()

Webdriver navigate method to open any webpage and navigating to forward and back options like moving or redirecting from one page to other pages as below.

Syntax & Example:

driver.navigate().to(“https://www.google.com”);
// It is an alternate to get() method to open an Url.

driver.navigate().forward(); 
// It move forward a page.

driver.navigate().back(); 
// It goes a page back.

driver.navigate().refresh();
 // It refresh the current page.

WebDriver Method : quit()

Quit method closes all open current window browsers in a system which is open by Selenium Webdriver test scripts.

Syntax: driver.quit();

WebDriver Method : switchTo()

Used to switch from one window to another window (or) window to a frame (or) frame to a window (or) window to an alert
Syntax:
driver.switchTo().window();
driver.switchTo().frame();
driver.switchTo().alert();

Difference between close( ) and quit( ) methods

  • close( ) WebDriver command closes the Browser window which is in focus.
    If there are more than one Browser window opened by the Selenium Automation, then the close( ) command will only close the Browser window which is having focus at that time. It won’t close the remaining Browser windows.
  • quit( ) WebDriver command is generally used to shut down the WebDriver instances. Hence it closes all the Browser windows that are opened by the Selenium Automation.
    close( ) and quit( ) work in the similar way when Selenium Automation opens only single Browser window. They differ in their functionality when there are more than one Browser windows opened by the Selenium Automation.

**For Detailed description of window, frame and alert handling you can refer corresponding posts.