Package org.openqa.selenium.chrome

Examples of org.openqa.selenium.chrome.ChromeDriver



public class ButtonDropdown {

  public static void main(String[] args) throws InterruptedException {
    WebDriver dr = new ChromeDriver();
   
    File file = new File("src/button_dropdown.html");
    String filePath = "file:///" + file.getAbsolutePath();
    System.out.printf("now accesss %s \n", filePath);
   
    dr.get(filePath);
    Thread.sleep(1000);
   
//    ��λtext��watir-webdriver�������˵�
//    ������ʾ�����˵�
    dr.findElement(By.linkText("Info")).click();
   
    (new WebDriverWait(dr, 10)).until(new ExpectedCondition<Boolean>() {
      public Boolean apply(WebDriver d){
        return d.findElement(By.className("dropdown-menu")).isDisplayed();
      }
    });
   
//    ͨ��ul�ٲ㼶��λ
    dr.findElement(By.className("dropdown-menu")).findElement(By.linkText("watir-webdriver")).click();
   
    Thread.sleep(1000);
    System.out.println("browser will be close");
    dr.quit()
  }
View Full Code Here



public class Form {

  public static void main(String[] args) throws InterruptedException {
    WebDriver dr = new ChromeDriver();
   
    File file = new File("src/form.html");
    String filePath = "file:///" + file.getAbsolutePath();
    System.out.printf("now accesss %s \n", filePath);
   
    dr.get(filePath);
    Thread.sleep(1000);
   
//    ѡ��checkbox
    dr.findElement(By.cssSelector("input[type=checkbox]")).click();
    Thread.sleep(1000);
   
//    ѡ��radio
    dr.findElement(By.cssSelector("input[type=radio]")).click();
    Thread.sleep(1000);
   
//    ѡ�������˵��е����һ��
    List<WebElement> options = dr.findElement(By.tagName("select")).findElements(By.tagName("option"));
    options.get(options.size() - 1).click();
    Thread.sleep(1000);
   
//    ����ύ��ť
    dr.findElement(By.cssSelector("input[type=submit]")).click();
   
    Alert alert = dr.switchTo().alert();
    System.out.println(alert.getText());
    alert.accept();
   
    Thread.sleep(1000);
    System.out.println("browser will be close");
    dr.quit()
  }
View Full Code Here


public class TitleAndUrl {

  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.printf("title of current page is %s\n", dr.getTitle());
    System.out.printf("url of current page is %s\n", dr.getCurrentUrl());
   
    System.out.println("browser will be close");
    dr.quit()
  }
View Full Code Here


public class Pagination {

  public static void main(String[] args) throws InterruptedException {
    WebDriver dr = new ChromeDriver();
   
    File file = new File("src/pagination.html");
    String filePath = "file:///" + file.getAbsolutePath();
    System.out.printf("now accesss %s \n", filePath);
   
    dr.get(filePath);
    Thread.sleep(1000);
   
//    获得所有分页的数量
//    -2是因为要去掉上一个和下一个
    int total_pages = dr.findElement(By.className("pagination")).findElements(By.tagName("li")).size() - 2;
    System.out.printf("Total page is %d\n", total_pages);
   
//    取当前页面的url以及当前页面是第几页
    WebElement current_page = dr.findElement(By.className("pagination")).findElement(By.className("active"));
    System.out.printf("Current page is %s\n", current_page.getText());
   
    Thread.sleep(1000);
    System.out.println("browser will be close");
    dr.quit()
  }
View Full Code Here


public class Attribute {

  public static void main(String[] args) throws InterruptedException {
    WebDriver dr = new ChromeDriver();
   
    File file = new File("src/attribute.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"));
   
//    获得tooltip的内容
    System.out.println(link.getAttribute("data-original-title"));
   
//    获取该链接的text
    System.out.println(link.getText());
   
    Thread.sleep(1000);
    System.out.println("browser will be close");
    dr.quit()
  }
View Full Code Here


public class AlertExample {

  public static void main(String[] args) throws InterruptedException {
    WebDriver dr = new ChromeDriver();
   
    File file = new File("src/alert.html");
    String filePath = "file:///" + file.getAbsolutePath();
    System.out.printf("now accesss %s \n", filePath);
   
    dr.get(filePath);
    Thread.sleep(1000);
   
//    ������ӵ���alert
    dr.findElement(By.id("tooltip")).click();
   
    Alert alert = dr.switchTo().alert();
    alert.accept();
           
    Thread.sleep(1000);
    System.out.println("browser will be close");
    dr.quit()
  }
View Full Code Here


public class SimpleLocate {

  public static void main(String[] args) throws InterruptedException {
    WebDriver dr = new ChromeDriver();
   
    File file = new File("src/checkbox.html");
    String filePath = "file:///" + file.getAbsolutePath();
    System.out.printf("now accesss %s \n", filePath);
   
    dr.get(filePath);
    Thread.sleep(1000);
   
//    选择所有的checkbox并全部勾上
    List<WebElement> checkboxes = dr.findElements(By.cssSelector("input[type=checkbox]"));
    for(WebElement checkbox : checkboxes) {
      checkbox.click();
    }
    dr.navigate().refresh();
   
//    打印当前页面上有多少个checkbox
    System.out.printf("%d\n", checkboxes.size());
   
//    选择页面上所有的input,然后从中过滤出所有的checkbox并勾选之
    List<WebElement> inputs = dr.findElements(By.tagName("input"));
    for(WebElement input : inputs){
      if(input.getAttribute("type").equals("checkbox")){
        input.click();
      }
    }
   
//    把页面上最后1个checkbox的勾给去掉
    List<WebElement> allCheckboxes = dr.findElements(By.cssSelector("input[type=checkbox]"));
    allCheckboxes.get(allCheckboxes.size() - 1).click();
   
    Thread.sleep(1000);
    System.out.println("browser will be close");
    dr.quit()
  }
View Full Code Here


public class Maximize {

  public static void main(String[] args) throws InterruptedException {
    WebDriver dr = new ChromeDriver();
    Thread.sleep(2000);
   
    System.out.println("maximize browser");
    dr.manage().window().maximize();
    Thread.sleep(2000);
   
    System.out.println("browser will be close");
    dr.quit()
  }
View Full Code Here


public class SimpleLocate {

  public static void main(String[] args) throws InterruptedException {
    WebDriver dr = new ChromeDriver();
   
    File file = new File("src/form.html");
    String filePath = "file:///" + file.getAbsolutePath();
    System.out.printf("now accesss %s \n", filePath);
   
    dr.get(filePath);
    Thread.sleep(2000);
   
//    by id
    dr.findElement(By.id("inputEmail")).click();
    Thread.sleep(1000);
   
//    by name
    dr.findElement(By.name("password"));
    Thread.sleep(1000);
   
//    by tagname
    String classOfForm = dr.findElement(By.tagName("form")).getAttribute("class");
    System.out.printf("%s\n", classOfForm);
    Thread.sleep(1000);
   
//    by link text
    WebElement link = dr.findElement(By.linkText("register"));
    ((JavascriptExecutor)dr).executeScript("$(arguments[0]).fadeOut().fadeIn()", link);
    Thread.sleep(1000);

//    by partial link test
    WebElement sameLink = dr.findElement(By.partialLinkText("reg"));
    ((JavascriptExecutor)dr).executeScript("$(arguments[0]).fadeOut().fadeIn()", sameLink);
    Thread.sleep(1000);
   
//    by css selector
    WebElement div = dr.findElement(By.cssSelector(".controls"));
    ((JavascriptExecutor)dr).executeScript("$(arguments[0]).fadeOut().fadeIn()", div);
    Thread.sleep(1000);
   
//    by xpath
    dr.findElement(By.xpath("/html/body/form/div[3]/div/label/input")).click();
    Thread.sleep(1000);
   
    System.out.println("browser will be close");
    dr.quit()
  }
View Full Code Here


public class SendKeys {

  public static void main(String[] args) throws InterruptedException {
    WebDriver dr = new ChromeDriver();
   
    File file = new File("src/send_keys.html");
    String filePath = "file:///" + file.getAbsolutePath();
    System.out.printf("now accesss %s \n", filePath);
   
    dr.get(filePath);
    Thread.sleep(1000);
   
//    copy content of A
    dr.findElement(By.id("A")).sendKeys(Keys.chord(Keys.CONTROL + "a"));
    Thread.sleep(1000);
    dr.findElement(By.id("A")).sendKeys(Keys.chord(Keys.CONTROL + "x"));
   
//    paste to B
    dr.findElement(By.id("B")).sendKeys(Keys.chord(Keys.CONTROL + "v"));
   
//    SendKeys to A
    dr.findElement(By.id("A")).sendKeys(Keys.chord("watir webdriver is better than selenium webdriver"));
   
    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.