Selenium Basic Methods

  • get() :It will load a new web page in the current browser window.

e.g. driver.get(“http://gmail.com”)

  • getCurrentUrl(): Gets a string representing the current URL that the browser is opened.

e.g. driver.getCurrentUrl();

  • getTitle(): Gets the title of the current web page.

e.g. driver.getTitle();

  • findElements() : Find all elements within the current page using the given mechanism
  • findElement():Find the first WebElement using the given method.
  • getPageSource():Get the source of the currently loaded page.
  • To(URL) : This methods Load a new web page in the current browser window.

e.g.


Webdriver driver= new FirefoxDriver();

driver.navigate().to("http://www.google.com");

 

  • Back() : To move back a single step in the web browser’s history

e.g.


WebDriver driver= new FirefoxDriver();

String URL="yahoo.com";

driver.navigate().to(URL); driver.findElement(By.linkText("Mail")).click(); driver.navigate().back();

 

  • Forward() : To move a single step forward in the web browser’s history.
WebDriver driver= new FirefoxDriver();

String URL="http://yahoo.com";

driver.navigate().to(URL); driver.findElement(By.linkText("Mail")).click(); driver.navigate().back();

Thread.sleep(1000);

driver.navigate().forward();

 

  • Refresh() : It refreshes the current web page
driver= new FirefoxDriver();

String URL="https:/login.yahoo.com/";

driver.navigate().to(URL);

driver.findElement(By.linkText("Sign up")).click();

Thread.sleep(1000);

driver.findElement(By.id("usernamereg-firstName")).sendKeys("amol");

driver.navigate().refresh();

  • close() : Close the current window, if there are multiple windows, it will close the current window which is active and quits the browser if it’s the last window opened currently.

e.g. driver.close();

  • quit(): Quits this driver instance, closing every associated window which is opened.

e.g. driver.quit();


Search

Subscribe to YouTube

Training on Selenium

Like us on facebook

Jobs

Jobs

Cooking with Amol