zoukankan      html  css  js  c++  java
  • 自动化java+webdriver常用的一些脚本

    简述 :写自动化常用的一些脚本

    (1)设置当前窗口为最大化

    driver.manage().window().maximize();

    (2)模拟键盘单机

    Actions action = new Actions(driver);

    action.click(driver.findElement(By.xpath("/HTML/BODY/DIV[2]/FORM/DIV[4]/BUTTON"))).build().perform();

    (3)设置睡眠等待时间为3秒

    public void logins() throws InterruptedException{

    Thread.sleep(3000);

    }

    (4)给文本赋值

    driver.findElement(by.xpath("/html/body/div[3]/div[1]/span/div/ul/li[2]/a")).sendkeys("123456");

    (5)鼠标悬浮在元素上

    Actions action=new Actions(dr);

    action.moveToElement(dr.findElement(By.xpath("/html/body/div[1]/div/div[2]/ul/li[2]/a/span"))).perform();

    (6)文件、图片上传

    dr.findElement(By.xpath("/html/body/div[3]/div[1]/span/div/ul/li[2]/a")).sendKeys("C:\\Users\\Public\\Pictures\\Sample Pictures\\图片格式\\jpg\\19.jpg");  //注意这里路径是反斜杠

    (7)窗口截图

    WebDriver driver = new ChromeDriver();
    driver.get("http://www.baidu.com");
    try {
    File srcFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
    FileUtils.copyFile(srcFile,new File("d:\\screenshot.png")); //指定图片的保存路径及文件名
    } catch (Exception e) {
    e.printStackTrace();
    }
    driver.quit();

  • 相关阅读:
    Java 数组算法列题解析
    Java数组总结
    go实现汉诺塔
    go实现归并排序
    css清除浮动深度解析
    jquery阻止事件冒泡
    java
    getComputedStyle/currentStyle/style之间的爱恨情仇
    js基础总结
    元素堆叠问题、z-index、position
  • 原文地址:https://www.cnblogs.com/caozq1/p/7804146.html
Copyright © 2011-2022 走看看