zoukankan      html  css  js  c++  java
  • selenium浏览器操作

    在元素定位中xpath使用的还算比较多,介绍一下常见的firfox和chrome浏览器插件安装

    一、浏览器定位工具安装

    1、firfox

    firfox比较简单,主要浏览器自带的定位功能也比较强大国内也比较好的支持插件安装

    1)安装

    我这里已经安装好了所以可以在"我的附加组件"里面查看,如果没有安装的话可以在"可用附加组件"中安装

    2)使用

     firepath和firefinder都可以定位元素,firepath可以在定位元素的时候生成xpath或者css,finefinder比较偏向验证xpath是否正确。F12用小光标指定要定位的元素。

    到firefinder里面验证的时候记得要去掉firepath里面的"."

     2、chrome

    chrome浏览器自带xpath功能直接F12用小光标找到元素,然后右击Copy->copy Xpath

     可以通过ctrl+F 输入刚刚copy的xpath

    二、浏览器启动

    安装浏览器的时候会自带驱动,如果浏览器不在系统默认路径下在代码里设置如下:

    1)firefox

    两种写法都可以

     DesiredCapabilities des = DesiredCapabilities.firefox();
     des.setCapability("webdriver.firefox.bin","C:\Program Files (x86)\Mozilla Firefox\firefox.exe");
     WebDriver driver = new FirefoxDriver(des); 

    或者

    System.setProperty("webdriver.firefox.bin","C:\Program Files (x86)\Mozilla Firefox\firefox.exe");
    WebDriver driver = new FirefoxDriver();
    driver.manage().window().maximize();

    2)chrome

    System.setProperty("webdriver.chrome.driver", "files\chromedriver.exe");  //指定驱动路径
    WebDriver driver = new ChromeDriver();

    3)IE

    System.setProperty("webdriver.ie.driver", "files\IEDriverServer.exe");
    WebDriver driver = new InternetExplorerDriver();

    参考:http://www.cnblogs.com/uslang/articles/5819116.html

  • 相关阅读:
    APP开发关于缓存
    SlidingMenu+Fragment实现当前最流行的侧滑
    深入理解dp px density
    HDU1847--Good Luck in CET-4 Everybody!(SG函数)
    【转】博弈论——acm
    HDU1846--Brave Game(巴什博弈)
    HDU2179--pi(麦金公式)
    HDU1026--Ignatius and the Princess I(BFS记录路径)
    HDU1237--简单计算器(栈的应用)
    HDU3398—String-(组合数)
  • 原文地址:https://www.cnblogs.com/applemoon/p/6136884.html
Copyright © 2011-2022 走看看