Run geckodriver before launching the browser
- Inorder to launch empty firefox browser,just create a object to browser class,it automatically launches a browser,bcoz constructor has the code to launch empty browser.
- get() is used to navigate to any web application URL,but URL should start with "http:" or "https:"
Note: Webdriver internally uses http or https protocol for browser communication.
Example as below:
import org.openqa.selenium.firefox.firefoxDriver;
public class SampleFirstTest {
System.setProperty("webDriver.gecko.Driver",c://....path u should give");
FirefoxDriver driver=new FirefoxDriver();
driver.get("https://facebook.com");
}
Webdriver basic Browser operation:
get()
navigate().to()
navigate().refresh();
navigate().back()
navigate().forward()
findElement()
findElements()
getTitle()
getCurrentUrl()
getPageSource()
getWindowHandles()
quit()
close()
manage().window().maximize()
manage().window().setsize()
manage().deleteAllCookies()
findElement(locators):
- findElement method is used to identify the element in GUI
- Technically findElement() is used to navigate entire html document and identify the object by taking locator as a refernce.
- findElement method throws "no such element excetion" if object is not available in "UI"
- findElement method always return webElement reference if object is available
- findElement method can identify the object based on 8 locators
8 Locators are below :
- id()
- name()
- xpath()
- cssselector()
- linkText()
- partialLinkText()
- className()
- tagName()
WebElement wb= driver.findElement(By.id("Email"));
//Perform action on webElement
wb.sendKeys("test@gmail.com");
All locators are static methods implemented inside the By class.
Example Program:
Class GmailLoginTest
{
public static void main(String[]args)throws InteruptedException {
System.setProperty("webDriver.gecko.Driver",c://....path u should give");
FirefoxDriver driver = new FirefoxDriver();
driver.get("http://www.gmail.com");
//Login
driver.findElement(By.id("Email")).sendKeys("give ur gmail");
driver.findElement(By.id("next")).click();
Thread.sleep(3000);
driver.findElement(By.name("password")).sendKeys("give password");
driver.findElement(By.id("signin")).click();
Thread.sleep(1000);
//logout
driver.findElement(By.xpath("//a[@class='take it out from inspectelement']")).click();
Thread.sleep();
driver.quit();
}
}
IIIASA in jaipur gives the best IAS coaching with best available help and helps in guiding the student to the best.
ReplyDeleteWant to know the best IAS coaching institute jaipur?
Well It is IIIASA.
Nice and Very useful information you have shared. Thank you for this wonderful sharing. Keep sharing.
ReplyDelete