Package org.openqa.selenium.chrome

Examples of org.openqa.selenium.chrome.ChromeDriver



public class OperateElement {

  public static void main(String[] args) throws InterruptedException {
    WebDriver dr = new ChromeDriver();
   
    File file = new File("src/operate_element.html");
    String filePath = "file:///" + file.getAbsolutePath();
    System.out.printf("now accesss %s \n", filePath);
   
    dr.get(filePath);
    Thread.sleep(1000);
   
//    click
    dr.findElement(By.linkText("Link1")).click();
    Thread.sleep(1000);
    dr.findElement(By.linkText("Link1")).click();
   
//    send_keys
    WebElement element = dr.findElement(By.name("q"));
    element.sendKeys("something");
    Thread.sleep(1000);
   
//    clear
    element.clear();
   
    Thread.sleep(1000);
    System.out.println("browser will be close");
    dr.quit()
  }
View Full Code Here



public class Get {

  public static void main(String[] args) throws InterruptedException {
    WebDriver dr = new ChromeDriver();
    Thread.sleep(2000);
   
    String url = "http://www.baidu.com";
    System.out.printf("now accesss %s \n", url);
    dr.get(url);
    Thread.sleep(2000);
   
    System.out.println("browser will be close");
    dr.quit()
  }
View Full Code Here


public class ResizeBrowser {

  public static void main(String[] args) {
    WebDriver dr = new ChromeDriver();
    dr.manage().window().setSize(new Dimension(240, 320));
    dr.get("http://www.3g.qq.com/");
    dr.quit();
  }
View Full Code Here


public class Upload {

  public static void main(String[] args) throws InterruptedException {
    WebDriver dr = new ChromeDriver();
   
    File file = new File("src/upload_file.html");
    String filePath = "file:///" + file.getAbsolutePath();
    System.out.printf("now accesss %s \n", filePath);
   
    dr.get(filePath);
    Thread.sleep(1000);
   
    dr.findElement(By.cssSelector("input[type=file]")).sendKeys("src/navs.html");
   
    Thread.sleep(1000);
    System.out.println("browser will be close");
    dr.quit()
  }
View Full Code Here


public class Css {

  public static void main(String[] args) throws InterruptedException {
    WebDriver dr = new ChromeDriver();
   
    File file = new File("src/css.html");
    String filePath = "file:///" + file.getAbsolutePath();
    System.out.printf("now accesss %s \n", filePath);
   
    dr.get(filePath);
    Thread.sleep(1000);
   
    WebElement link = dr.findElement(By.id("tooltip"));
   
    System.out.println(link.getCssValue("color"));
   
    System.out.println(dr.findElement(By.tagName("h3")).getCssValue("font"));
   
    Thread.sleep(1000);
    System.out.println("browser will be close");
    dr.quit()
  }
View Full Code Here


public class Breadcrumb {

  public static void main(String[] args) throws InterruptedException {
    WebDriver dr = new ChromeDriver();
   
    File file = new File("src/breadcrumb.html");
    String filePath = "file:///" + file.getAbsolutePath();
    System.out.printf("now accesss %s \n", filePath);
   
    dr.get(filePath);
    Thread.sleep(1000);
   
//    获得其父层级
    List<WebElement> ancestors = dr.findElement(By.className("breadcrumb")).findElements(By.tagName("a"));
    for(WebElement link : ancestors){
      System.out.println(link.getText());
    }
   
//    获取当前层级
//    由于页面上可能有很多class为active的元素
//    所以使用层级定位最为保险
    WebElement current = dr.findElement(By.className("breadcrumb")).findElement(By.className("active"));
    System.out.println(current.getText());
   
    Thread.sleep(1000);
    System.out.println("browser will be close");
    dr.quit()
  }
View Full Code Here


public class CookieExample {

  public static void main(String[] args) throws InterruptedException {
    WebDriver dr = new ChromeDriver();

    String url = "http://www.baidu.com";
    System.out.printf("now accesss %s \n", url);
   
    dr.get(url);
    Thread.sleep(2000);
   
    System.out.println(dr.manage().getCookies());
   
    dr.manage().deleteAllCookies();
   
    Cookie c1 = new Cookie("BAIDUID", "xxxxxxxxxx");
    Cookie c2 = new Cookie("BDUSS", "xxxxxxxxxx");
    dr.manage().addCookie(c1);
    dr.manage().addCookie(c2);
   
    System.out.println("browser will be close");
   
    dr.quit()
  }
View Full Code Here


public class ForwardAndBack {

  public static void main(String[] args) throws InterruptedException {
    WebDriver dr = new ChromeDriver();
    Thread.sleep(2000);
   
    String firstUrl = "http://www.baidu.com";
    System.out.printf("now accesss %s \n", firstUrl);
    dr.get(firstUrl);
    Thread.sleep(1000);
   
    String secondUrl = "http://www.soso.com";
    System.out.printf("now accesss %s \n", secondUrl);
    dr.get(secondUrl);
    Thread.sleep(1000);

    System.out.printf("now back to  %s \n", firstUrl);
    dr.navigate().back();
    Thread.sleep(1000);
   
    System.out.printf("forward to  %s \n", secondUrl);
    dr.navigate().forward();
    Thread.sleep(1000);
   
    System.out.println("browser will be close");
    dr.quit()
  }
View Full Code Here


public class StartBrowser {

  public static void main(String[] args) {
    WebDriver dr = new ChromeDriver();
  }
View Full Code Here


public class LevelLocate {

  public static void main(String[] args) throws InterruptedException {
    WebDriver dr = new ChromeDriver();
   
    File file = new File("src/level_locate.html");
    String filePath = "file:///" + file.getAbsolutePath();
    System.out.printf("now accesss %s \n", filePath);
   
    dr.get(filePath);
    Thread.sleep(1000);
   
    dr.findElement(By.linkText("Link1")).click();
   
    (new WebDriverWait(dr, 10)).until(new ExpectedCondition<Boolean>(){
      public Boolean apply(WebDriver d){
        return d.findElement(By.id("dropdown1")).isDisplayed();
      }
    } );
   
    WebElement menu = dr.findElement(By.id("dropdown1")).findElement(By.linkText("Another action"));
    (new Actions(dr)).moveToElement(menu).perform();
   
    Thread.sleep(1000);
    System.out.println("browser will be close");
    dr.quit()
  }
View Full Code Here

TOP

Related Classes of org.openqa.selenium.chrome.ChromeDriver

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.