java+selenium+Firefox自动化测试框架

此篇没有太多参考的价值,不够详细.有时间补充


FireFox下载28-32版本的,我下载的是,较高版本不支持FireBug和FirePath

添加组件

java+selenium+Firefox自动化测试框架_第1张图片

搜索安装FireBug

java+selenium+Firefox自动化测试框架_第2张图片

安装FirePath插件

java+selenium+Firefox自动化测试框架_第3张图片

下载一下红框内的包

java+selenium+Firefox自动化测试框架_第4张图片

其中selenium-server-3.1.0包内包含的文件

java+selenium+Firefox自动化测试框架_第5张图片

将第三方jar包(lib和)全部添加到项目中.

创建项目的类

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

public class demo {
    public static void main(String[] args) {
        WebDriver driver;
        //火狐的安装位置
        System.setProperty("webdriver.firefox.bin","D:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
        //加载驱动
        System.setProperty("webdriver.firefox.marionette","D:\\jar\\seleniumforFirefox\\geckodriver-v0.14.0-win64\\geckodriver.exe");
        driver=new FirefoxDriver();
        driver.get("https://www.baidu.com");
    }
}

另一个例子:

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class ActionSelenium {
    public WebDriver driver;

    public void InitDriver() {
        System.setProperty("webdriver.firefox.bin", "D:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
        //System.setProperty("webdriver.chrome.bin","C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe");
       // System.setProperty("webdriver.chrome.driver", "D:\\jar\\seleniumjar\\chromedriver_win32\\chromedriver.exe");
        System.setProperty("webdriver.firefox.marionette","D:\\jar\\seleniumforFirefox\\geckodriver-v0.14.0-win64\\geckodriver.exe");
        //driver = new ChromeDriver();
        driver=new FirefoxDriver();
        driver.get("https://www.imooc.com/user/newlogin/from_url");
        driver.manage().window().maximize();
    }
    public void inputBox(){
        driver.findElement(By.name("email")).sendKeys("[email protected]");
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        driver.findElement(By.name("email")).clear();
        String s=driver.findElement(By.name("email")).getAttribute("placeholder");
        System.out.print(s);
    }

    public static void main(String[] args) {
        ActionSelenium as=new ActionSelenium();
        as.InitDriver();
        as.inputBox();
    }
}

下一个例子

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

import java.util.Collections;
import java.util.List;

public class selenium1 {
    public static void main(String[] args) {
        System.setProperty("webdriver.firefox.bin", "D:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
        System.setProperty("webdriver.firefox.marionette","D:\\jar\\seleniumforFirefox\\geckodriver-v0.14.0-win64\\geckodriver.exe");
        WebDriver driver = new FirefoxDriver();
        driver.get("http://www.imooc.com/user/newlogin/form_url");
        driver.findElement(By.tagName("input")).sendKeys("[email protected]");
        driver.findElement(By.name("password")).sendKeys("xu221168");
        driver.findElement(By.id("auto-signin")).click();
        driver.findElement(By.linkText("立即注册")).click();
        driver.findElement(By.partialLinkText("直接")).click();
        //driver.findElement(By.tagName("input")).sendKeys("[email protected]");
        driver.findElement(By.name("password")).sendKeys("xu221168");
        //driver.findElement(By.className("btn-red")).click();
        driver.manage().window().maximize();
        driver.get("https://www.imooc.com/");
        driver.findElement(By.className("search-input")).click();
        driver.findElement(By.className("search-input")).sendKeys("ssss");
        WebElement element = driver.findElement(By.className("nav-item"));
        List elements = Collections.singletonList(element.findElement(By.tagName("li")));
        elements.get(3).click();


    }
}




你可能感兴趣的:(java+selenium)