zoukankan      html  css  js  c++  java
  • 第2章 Selenium2-java 测试环境搭建

       

    2.1  Window下环境搭建

      2.1.1 安装Java

      2.1.2 安装Eclipse

      (网上资源很多,就不详将了)。

     2.1.3 下载Java版的Selenium包。

     下载地址:http://docs.seleniumhq.org/download/

      提供一下百度网盘下载地址: http://pan.baidu.com/share/link?shareid=1233226792&uk=375774229

      

    2.1.4 创建第一个Java程序

        eclipse导入selenium的所有jar包。

      简单步骤“

        ——》    ——》——》——》

    2.2  编写第一个自动化脚本

    package com.cy.selenium;
    
    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.firefox.FirefoxDriver;
    
    
    public class Test01 {
        public static void main(String[] args) {       
            System.out.println("start selenium");
            WebDriver driver=new FirefoxDriver();// 用WebDriver new Firefox浏览器的驱动给变量driver,相当于driver拿到了Firefox浏览器的控制权。
           // driver.manage().window().maximize();
            driver.get("https://www.baidu.com/");
            driver.findElement(By.id("kw")).sendKeys("selenium2 java");
            driver.findElement(By.id("su")).click();
            try {
                driver.wait(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }finally {
                driver.close();
            }
        }
    
    }

     运行这段代码,就会出现效果了。(Fiefox浏览器默认安装到C盘)。

    还有一些问题可能是你的浏览器不兼容的问题。

    这里我的selenium2.45,火狐使用的是36的版本。

    浏览器没有安装在C盘的话,使用 System的setProperty()方法指定浏览器的路径,eg:

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

     我本来就是学习java的。

       

  • 相关阅读:
    leetcode-38.报数
    leetcode-35.搜索插入位置
    leetcode-27.移除元素
    leetcode-26.删除重复数组中的重复项
    leetcode-20.有效的括号
    leetcode-973最接近原点的K个点
    leetcode-14最长公共前缀
    leetcode-13罗马字符转整数
    MFC俄罗斯方块
    leetcode-9.回文数(水仙花数)
  • 原文地址:https://www.cnblogs.com/hellokitty1/p/6292360.html
Copyright © 2011-2022 走看看