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();
    }

    
    

    }

     
  • 相关阅读:
    《痕迹识人,面试读心》培训总结之一
    傲游与视频网站广告之战的思考
    EMLS项目推进思考
    二级证丢失如何找回
    Mathematica 讲座
    泊松方程解法
    Windows核心编程-作业
    Win7多用户同时登陆
    C语言文件操作类型速查
    openMP的一点使用经验
  • 原文地址:https://www.cnblogs.com/wangyinxu/p/6399863.html
Copyright © 2011-2022 走看看