Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Selenium Webdriver methods

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 772
    Comment on it

    To perform operation on web browser and with web element (Ex: URL, Title, buttons, links,check box, edit boxes, radio buttons etc) Webdriver provides many methods(Ex: URL, Title, buttons, links,check box, edit boxes, radio buttons etc).

     

    • There are some common methods which are generally used on eclipse.
    • When we enter driver in eclipse and click on space bar, we get  all the below methods on screen.

     

    1. get()
    2. getCurrentUrl();
    3. getTitle()
    4. getPageSource()
    5. findElements()
    6. findElement()
    7. close()
    8. quit()

    get(url): It will launch specified URL in the browser window.
    syntax: driver.get(url)
    Example: driver.get("https:google.com/")

     

    getCurrentUrl() : It will return a string representing the current URL of the page which is loaded in browser.
    syntax: getCurrentUrl()
    Example: driver.getcurrentUrl();
    system.out.println(url);

     

    getTitle(): It will be return the title of the current webpage.
    Syntax: getTitle()
    Example: driver.getTitle();

     

    getPageSource(): It will return the HTML page source of current web page.
    Syntax: getPageSource()
    Example: driver.getPageSource();

     

    findElements(): It will return  all the elements or an empty list if nothing matches withing the page.
    Syntax: findElements(By by)
    Example: driver.findElements(By.xpath("//");

     

    findElement(): It will return first matching element using the given method  or throw the exception if no matching elements found
    Syntax: WebElement findElement(By by)
    Example: driver.findElement(By.xpath("//");

     

    close(): It will close only current focused window.
    Example: driver.close();

     

    quit(): It will close all the windows which are opened by webdriver
    Example: driver.quit();

     

    Navigation methods:

    navigate().to()method: It will launch the webpage in current window.


    navigate().back()method : Suppose used has opened multiple web page page A, Page B and Page C. If user wants to return his previously opened page then he will use this method to navigate to back.


    navigate().forward()method: Its is same as clicking on forward button on browser. It moves the single item forward in browser history.


    navigate().refresh() method: It refresh the current webpage
    Example: driver.get("https:google.com/");
    driver.navigate().refresh();

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: