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

  • 相关阅读:
    ansible笔记(11):初识ansible playbook(二)
    Linux下查看占用CPU与内存最高的进程
    ansible笔记(10):初识ansible playbook
    AbpZero Http 模式下 Chrome浏览器因Cookie 不能登录
    Tomcat 8443&8080 并存
    接入腾讯cos文件存储
    安卓包打渠道标签
    java Android与PHP encode的区别
    thinkphp常用
    phalcon task任务
  • 原文地址:https://www.cnblogs.com/applemoon/p/6136884.html
Copyright © 2011-2022 走看看