SuperPatrick教程之如何使webDriver与SuperPatrick结合实现互补的例子(java语言)---晒酷学院

晒酷学院:https://shareku.ke.qq.com/
微信号:添加请注明晒酷学院            QQ群:979438600
微信号:添加请注明晒酷学院         QQ群:979438600

这里直接给代码例子,大家自己体会,不过需要注意的是,以下代码运行时的Firefox版本是60.0.1,OS是Win 10,如果浏览器版本不一样,OS不一样,具体界面可能也会不一样,这个时候就需要大家用SuperPAtrick定位器自己微调代码:

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

import com.sun.jna.Library;
import com.sun.jna.Native;

public class WebDriverDemo {
    public interface SuperPatrickLibrary extends Library {
        void findElement(String pStrId, String pStrName, String pStrClassName, String controlType);
        void sendKeys(String pKeysString);
        void sendShortCutKeys(String pKeysString);
    }

    public static void main(String[] args) throws InterruptedException {
        System.setProperty("jna.encoding","GBK");
        // TODO Auto-generated method stub
        String dllPath = "C:/1/SuperPatrickLibrary.dll";
        SuperPatrickLibrary superpatrick = (SuperPatrickLibrary) Native.loadLibrary(dllPath, SuperPatrickLibrary.class);
        superpatrick.findElement("307","显示桌面","","Button");
        WebDriver driver = new FirefoxDriver();

        String url ="http://www.autotestops.com/test/upload.html";
        driver.get(url);
        Thread.sleep(5000);
        superpatrick.findElement("","Firefox","","Button");
        superpatrick.findElement("","定制…","","Button");
        Thread.sleep(500);
        superpatrick.findElement("","工具栏","","Button");
        Thread.sleep(500);
        superpatrick.findElement("","菜单栏","","MenuItem");
        Thread.sleep(500);
        superpatrick.findElement("","完成","","Button");

      Thread.sleep(500);
        superpatrick.findElement("","历史","","MenuItem");
        superpatrick.findElement("","清除最近的历史记录…    Ctrl+Shift+Del","","MenuItem");
        Thread.sleep(1000);
        superpatrick.findElement("","要清除的时间范围:","","ComboBox");
        superpatrick.findElement("","最近一小时","","ListItem");
        superpatrick.findElement("","详细信息","","Button");
        Thread.sleep(500);
        superpatrick.findElement("","浏览和下载历史","","Text");
        superpatrick.findElement("","表单和搜索历史","","Text");
        superpatrick.findElement("","登录状态","","Text");
        Thread.sleep(500);
        System.out.println("设置完成");
        superpatrick.findElement("","立即清除","","Button");
        Thread.sleep(5000);

      superpatrick.findElement("","浏览…","","Button");
        Thread.sleep(500);
        superpatrick.findElement("1001","地址: 桌面","ToolbarWindow32","ToolBar");
        String path = System.getProperty("user.dir");
        superpatrick.sendKeys(path);
        superpatrick.sendShortCutKeys("{Return}");
        superpatrick.findElement("1148","文件名(N):","ComboBox","ComboBox");
        superpatrick.sendKeys("1.jpg");
        Thread.sleep(500);
        superpatrick.findElement("1","打开(O)","Button","Button");
      driver.quit();
    }

}

从以上示例代码可以看出,SuperPtrick和webdriver完全互补,webdriver超出浏览器范围的部分将无能为力,而SuperPatrick可以弥补这个欠缺,同时在定位浏览器页面元素的时候,webdriver搞不定的时候,不妨试试SuperPatrick, 常常可以帮你搞定webdriver很难处理的问题,而且SuperPatrick不会改变webdriver内部任何状态,webdriver可以继续处理剩下的问题。
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值