zoukankan      html  css  js  c++  java
  • 自动化框架FluentLenium学习

    github地址:https://github.com/FluentLenium/FluentLenium

    常用的页面控件操作方法(element需要先通过css selector找到):

    [button]              button.click();

    1 @FindBy(css = "#searchBtn")
    2 private FluentWebElement searchBtn;

    [input]              fill("input[name='name']").with(name);

    [checkbox]          find("input[type=checkbox]").click();

    [radionbutton]      find("input[type=radio]").click();

    [file upload]      element.getElement().sendKeys(filePath);

    [selector]                 fillSelect("select[name='year']").withText("2014");

    [select checkbox]      //下拉复选框

    这种情况没有直接的方法使用,一般是点击两次达到复选的结果,封装的方法如下:

    1 protected void multiSelect(String selector, List<String> texts) {
    2     find(selector + " + div .multiselect").click();
    3     for (String text : texts) {
    4         await().atMost(5, TimeUnit.SECONDS).until(selector + " + div .multiselect-container").areDisplayed();
    5         find(selector + " + div .multiselect-container").find(".checkbox", withText(text)).click();
    6     }
    7 }

     [时间控件]

    如果时间控件是可以直接输入的话,可以用[input]控件的方法.

    但是如果不能直接输入,必须得点击选择的话,可以使用js来赋值,如下:

    1 executeScript("document.getElementsByName('startTime')[0].value=" + """ + startTime + """ + ";");

     [下载]

    下载需要先设置Firefox浏览器的属性,如下:

    1 FirefoxProfile firefoxProfile = new FirefoxProfile();
    2 String userHome = System.getProperty("user.home");
    3 firefoxProfile.setPreference("browser.download.dir", userHome + "/Downloads");
    4 firefoxProfile.setPreference("browser.download.folderList", 2);
    5 firefoxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/pdf, " +
    6         "application/octet-stream, application/vnd.ms-excel, text/csv, application/zip");
    7 firefoxProfile.setPreference("browser.download.manager.showWhenStarting", false);
    8 return new FirefoxDriver(firefoxProfile);
  • 相关阅读:
    HTML <input> 标签的 maxlength 属性
    HTTP 方法:GET 对比 POST
    怎么在html页面和js里判断是否是IE浏览器
    一行神奇的javascript代码
    c# 数据库批量插入数据SqlBulkCopy 示例
    c# 多线程调用窗体上的控件 示例
    sqlserver查找使用了某个字段的所有存储过程
    SQL Server 数据库性能优化
    SQL语句的执行过程
    Sql Server- 性能优化辅助指标SET STATISTICS TIME ON和SET STATISTICS IO ON
  • 原文地址:https://www.cnblogs.com/shevche/p/4194588.html
Copyright © 2011-2022 走看看