zoukankan      html  css  js  c++  java
  • webdriver---API---(java版) the fifth part

    1、拖拽页面元素

     //向下拖动10个像素,共拖动5次
          for(int i=0;i<5;i++){
              new Actions(driver).dragAndDropBy(driver.findElement(By.id('stb')), o, 10)
          }
          //向右拖动10个像素,共拖动5次
          for(int i=0;i<5;i++){
              new Actions(driver).dragAndDropBy(driver.findElement(By.id('stb')), 1o, 0)
          }

    2、查看页面元素属性

    String inputText=driver.findElement(By.id("query")).getAttribute("value");

    3、获取页面CSS属性

    WebElement input =driver.findElement(By.id("query"));
          String inputwidth=input.getCssValue("width");
          Assert.assertEquals("529", inputwidth);

    4、隐式等待

    driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);

    5、常用显式等待

    
    

    package cn.gloryroad;

    
    

    import org.testng.annotations.Test;
    import java.io.File;
    import org.testng.annotations.BeforeMethod;
    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.chrome.ChromeDriver;
    import org.openqa.selenium.support.ui.WebDriverWait;
    import org.testng.Assert;
    import org.testng.annotations.AfterMethod;
    import org.openqa.selenium.support.ui.ExpectedCondition;

    
    

    public class ApiTest2 {
    public WebDriver driver;
    String baseUrl;
    @Test
    public void operateCheckBox() {
    File file = new File("D:\workspace\WebDriver-API\src\wait.html");
    String filepath=file.getAbsolutePath();
    System.out.printf("now accesss %s ", filepath);
    driver.get(filepath);
    WebElement myDynamicElement = (new WebDriverWait(driver, 10))
    .until(new ExpectedCondition <WebElement>(){
    @Override
    public WebElement apply (WebDriver d) {
    return d.findElement(By.xpath("//*[@type='text']"));
    }
    });
    Assert.assertEquals("今年夏天西瓜相当甜!", myDynamicElement.getAttribute("value"));
    }
    @BeforeMethod
    public void beforeMethod() {
    System.setProperty("webdriver.chrome.driver", "C:\chromedriver\chromedriver.exe");
    driver =new ChromeDriver();
    }

    
    

    @AfterMethod
    public void afterMethod() {
    try{
    Thread.sleep(3000);
    }catch(InterruptedException e){
    e.printStackTrace();
    }
    driver.quit();
    }

    
    

    }

     
  • 相关阅读:
    生成器和推导式
    闭包
    python
    python初识函数二
    python函数初识
    python文件操作二
    文件操作
    python集合,深浅copy
    Python安装、配置图文详解
    jsDoc 使用及配置!
  • 原文地址:https://www.cnblogs.com/wangyinxu/p/6399863.html
Copyright © 2011-2022 走看看