Navigation
Loading a web page in a current browser window
- driver.get("www.google.com")
- driver.navigate().to("www.google.com")
- driver.navigate().to("www.google.com")
Move back & forward
- Driver.Navigate().Back()
- Driver.Navigate().Forward()
Refresh page
- Driver.Navigate().Refresh()
Locating web elements
By class
- Id
- driver.findElement(By.id(”some_id”));
- ClassName
- driver.findElement(By.className(”some_class_name”));
- LinkText
- driver.findElement(By.linkText(”Signin”));
- PartialLinkText
- driver.findElement(By.partiallinkText(”Sign”));
- Name
- driver.findElement(By.name(”password”));
- TagName
driver.findElement(By.tagName(”label”));- CssSelector
- Absolute path
–driver.findElement(By.cssSelector(”html>body>div>p>input”)); - Relative path
–driver.findElement(By.cssSelector(”input”)); - Classselection
–driver.findElement(By.cssSelector(”.login”)); - XPath
- Absolute path
–driver.findElement(By.xpath(”html/body/p/input”)); - Relative path
–driver.findElement(By.xpath(”//input”)); - Attribute selection
–driver.findElement(By.xpath(”//input[@id=’username’]”));
Synchronization
Page Load Timeout
- driver.manage().timeouts(). pageLoadTimeout(30, TimeUnit.SECONDS);
Explicit Wait
- WebDriverWaitwait = new WebDriverWait(driver, TIME_OUT); wait.until(ExpectedConditions.method);
Window Handling
Handles
- String windowHandle= driver.getWindowHandle(); Iterator<String> windowIterator=browser.getWindowHandles();
- SwitchTo : driver.switchTo().window(windowHandle);