Package org.openqa.selenium.chrome

Examples of org.openqa.selenium.chrome.ChromeDriver



public class Status {

  public static void main(String[] args) throws InterruptedException {
    WebDriver dr = new ChromeDriver();
   
    File file = new File("src/status.html");
    String filePath = "file:///" + file.getAbsolutePath();
    System.out.printf("now accesss %s \n", filePath);
   
    dr.get(filePath);
    Thread.sleep(1000)
   
    WebElement textField = dr.findElement(By.name("user"));
    System.out.println(textField.isEnabled());
   
//    直接用isEnabled方法去判断该button的话返回的会是true
//    这是因为button是使用css方法去disabled的,并不是真正的disable
//    这时候需要判断其class里是否有disabled这值来判断其是否处于disable状态
    System.out.println(dr.findElement(By.className("btn")).isEnabled());
   
//    隐藏掉textField
//    判断其是否显示
    ((JavascriptExecutor)dr).executeScript("$(arguments[0]).hide()", textField);
    System.out.println(textField.isDisplayed());
   
//    使用click方法选择raido
    WebElement radio = dr.findElement(By.name("radio"));
    radio.click();
    System.out.println(radio.isSelected());
   
    try{
      dr.findElement(By.id("none"));
    } catch(NoSuchElementException e){
      System.out.println("element does not exist");
    }
   
    Thread.sleep(1000);
    System.out.println("browser will be close");
    dr.quit()
  }
View Full Code Here


import org.openqa.selenium.support.ui.WebDriverWait;

public class Modal {

  public static void main(String[] args) throws InterruptedException {
    WebDriver dr = new ChromeDriver();
   
    File file = new File("src/modal.html");
    String filePath = "file:///" + file.getAbsolutePath();
    System.out.printf("now accesss %s \n", filePath);
   
    dr.get(filePath);
    Thread.sleep(1000);
   
//    �򿪶Ի���
    dr.findElement(By.id("show_modal")).click();
   
    (new WebDriverWait(dr, 10)).until(
        new ExpectedCondition<Boolean>() {
                    public Boolean apply(WebDriver d) {
                        return d.findElement(By.id("myModal")).isDisplayed();
                    }
                }
    );
   
//     ����Ի����е�����
//     ���ڶԻ����е�Ԫ�ر��ɰ����ڵ���ֱ�ӵ���ᱨ Element is not clickable�Ĵ���
//     ����ʹ��js��ģ��click
//     ��watir-webdriver��ֻ��Ҫfire_event(:click)�Ϳ�����
    WebElement link = dr.findElement(By.id("myModal")).findElement(By.id("click"));
    ((JavascriptExecutor)dr).executeScript("$(arguments[0]).click()", link);
   
    Thread.sleep(1000);
    System.out.println("browser will be close");
    dr.quit()
  }
View Full Code Here


public class CloseBrowser {

  public static void main(String[] args) {
    WebDriver dr = new ChromeDriver();
    System.out.println("browser will be closed");
   
    dr.quit()
    System.out.println("browser is closed");
  }
View Full Code Here


public class Js {

  public static void main(String[] args) throws InterruptedException {
    WebDriver dr = new ChromeDriver();
   
    File file = new File("src/js.html");
    String filePath = "file:///" + file.getAbsolutePath();
    System.out.printf("now accesss %s \n", filePath);
   
    dr.get(filePath);
    Thread.sleep(1000);
   
//    ��ҳ����ֱ��ִ��js
    ((JavascriptExecutor)dr).executeScript("$('#tooltip').fadeOut();");
    Thread.sleep(1000);
   
//    ���Ѿ���λ��Ԫ����ִ��js
    WebElement button = dr.findElement(By.className("btn"));
    ((JavascriptExecutor)dr).executeScript("$(arguments[0]).fadeOut();", button);
     
   
    Thread.sleep(1000);
    System.out.println("browser will be close");
    dr.quit()
  }
View Full Code Here


public class Navs {

  public static void main(String[] args) throws InterruptedException {
    WebDriver dr = new ChromeDriver();
   
    File file = new File("src/navs.html");
    String filePath = "file:///" + file.getAbsolutePath();
    System.out.printf("now accesss %s \n", filePath);
   
    dr.get(filePath);
    Thread.sleep(1000);
   
//    ����1���㼶��λ���ȶ�λul�ٶ�λli
    dr.findElement(By.className("nav")).findElement(By.linkText("About")).click();
    Thread.sleep(1000);
   
//    ����2: ֱ�Ӷ�λlink
    dr.findElement(By.linkText("Home")).click();
   
    Thread.sleep(1000);
    System.out.println("browser will be close");
    dr.quit()
  }
View Full Code Here


public class ButtonGroup {

  public static void main(String[] args) throws InterruptedException {
    WebDriver dr = new ChromeDriver();
   
    File file = new File("src/button_group.html");
    String filePath = "file:///" + file.getAbsolutePath();
    System.out.printf("now accesss %s \n", filePath);
   
    dr.get(filePath);
    Thread.sleep(1000);
   
//    ��λtext��second�İ�ť
    List<WebElement> btns = dr.findElement(By.className("btn-group")).findElements(By.className("btn"));
   
    for(WebElement btn : btns){
      if(btn.getText().equals("second")){
        btn.click();
        break;
      }
    }
   
    Thread.sleep(1000);
    System.out.println("browser will be close");
    dr.quit()
  }
View Full Code Here


public class Frame {

  public static void main(String[] args) throws InterruptedException {
    WebDriver dr = new ChromeDriver();
   
    File file = new File("src/frame.html");
    String filePath = "file:///" + file.getAbsolutePath();
    System.out.printf("now accesss %s \n", filePath);
   
    dr.get(filePath);
    Thread.sleep(1000);
   
//     �ȵ�f1�ٵ�f2
    dr.switchTo().frame("f1");
    dr.switchTo().frame("f2");
//    ��f2�еİٶȹؼ����ı�������������
    dr.findElement(By.id("kw")).sendKeys("watir-webdriver");
    Thread.sleep(1000);
   
//    ֱ����������frame
    dr.switchTo().defaultContent();

//    �ٵ�f1
    dr.switchTo().frame("f1");
    dr.findElement(By.linkText("click")).click();
   
    Thread.sleep(1000);
    System.out.println("browser will be close");
    dr.quit()
  }
View Full Code Here

            capabilities
        );
    }

    private WebDriver localChromeBrowser() {
        WebDriver driver = new ChromeDriver();

        return driver;
    }
View Full Code Here

    }

    @Provides
    @Singleton
    WebDriver getDefaultWebDriver() {
        ChromeDriver chromeDriver = new ChromeDriver();
        chromeDriver.manage().timeouts().implicitlyWait(2L, TimeUnit.SECONDS);
        return chromeDriver;
    }
View Full Code Here

            case IE:
                System.setProperty("webdriver.ie.driver", TEST_CLASSES_PATH + "//IEDriverServer.exe");
                return new InternetExplorerDriver();
            case GC:
                System.setProperty("webdriver.chrome.driver", TEST_CLASSES_PATH + "//chromedriver");
                return new ChromeDriver();
            case OPERA:
                return new OperaDriver();
            case HTMLUNIT:
                return new HtmlUnitDriver();
            default:
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.