zoukankan      html  css  js  c++  java
  • Selenium FirefoxDriver总结

    新建一个

    WebDriver driver = new FirefoxDriver();

    Firefox目录变更

    System.setProperty("webdriver.firefox.bin","D:/Program Files/Mozilla Firefox/firefox.exe");

    开URL

    Driver.get(url);
    Driver.Navigation.to(url);

    设置firefox

    1.新建一个 firefox -p 一般默认在:

    C:UsersAdministratorAppDataRoamingMozillaFirefoxProfiles

    2.在代码里引用这个profile

    File F = new File("C:\Users\Administrator\AppData\Roaming\Mozilla\Firefox\Profiles\9xhxx9r7.Selenium");
    FirefoxProfile profile = new FirefoxProfile(file);
    WebDriver driver = new FirefoxDriver(profile);

    加载插件

    File file = new File("files/firebug-2.0.7-fx.xpi");
    FirefoxProfile profile = new FirefoxProfile();
    try{
        profile.addExtension(file);
    }catch(Exception e){
       e.printStackTrace();
    }
    WebDriver driver = new FirefoxDriver(profile);

    通过about:config可以看到firefox的设置,可以通过代码改变, 有些设置直接可以通过firefox profile来设置

            //设置代理参数
    profile.setPreference("network.proxy.type", 1);
    profile.setPreference("network.proxy.http", proxyIp);
    profile.setPreference("network.proxy.http_port", proxyPort);
            
            //设置默认下载路径
    profile.setPreference("browser.download.folderList", 2);
    profile.setPreference("browser.download.dir", "D:\");

    capabilities的设置

    DesiredCapabilities capabilities = new DesiredCapabilities(); 
    DesiredCapabilities capabilities = DesiredCapabilities.firefox();
    capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
    driver = new FirefoxDriver(capabilities);

    这个capabilities是启动一个session必备的,是对所有driver都可以设置的,而firefoxprofile只有firefox只适用firefox

    Driver的timeout设置

    页面加载timeout
    driver.manage().timeouts().pageLoadTimeout(pageLoadTimeout, TimeUnit.SECONDS);
    找对象的timeout,动态找
    driver.manage().timeouts().implicitlyWait(waitTimeout, TimeUnit.SECONDS);
    脚本执行的timeout
    driver.manage().timeouts().setScriptTimeout(scriptTimeout, TimeUnit.SECONDS);

    如果想在页面没有加载完成的情况下就点击或者识别元素,用finally

     FirefoxDriver在selenium3的时候已经被弃用了,FirefoxDriver原理是用firefox的add-on来实现对浏览器的控制。

    更新后目前用的是geckodriver.exe,是通过geckodriver把W3 WebDriver wire protocol翻译成Marionette可以识别的协议接口,最终通过Marionette来实现对浏览器的控制。

  • 相关阅读:
    网上常见的分享功能, 比如 点击分享到 人人 微博 空间 等都是怎么做的...
    qq客服代码实现过程
    cnzz友盟怎么安装网站统计代码监控网站流量
    本地部署151688过程记录
    本地部署151688过程记录20110526
    梦里秦淮:互联网商业模式≠成功
    要远离这些平台网站
    阿里旺旺新老版本共存
    豆皮拖鞋穿著確實感覺不太舒服,磨腳,好看是好看,還是沒有哥倫比亞好
    深圳批发市场有哪些好的呢?
  • 原文地址:https://www.cnblogs.com/goldenRazor/p/4979042.html
Copyright © 2011-2022 走看看