码迷,mamicode.com
首页 > 其他好文 > 详细

Selenium 打开百度,简单代码

时间:2017-06-02 14:50:04      阅读:733      评论:0      收藏:0      [点我收藏+]

标签:app   百度   路径   http   ati   driver   baidu   pack   .exe   

火狐浏览器

 

package com.selenium.Glen;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.*;

public class firefox {

    private static WebDriver driver;

    public static void main(String[] args) {
        
        //如果火狐浏览器没有默认安装在C盘,需要制定其路径
        System.setProperty("webdriver.firefox.bin", "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
        WebDriver driver = new FirefoxDriver();
       driver.get("http://www.baidu.com/");
                
        driver.manage().window().maximize();
        
        WebElement txtbox = driver.findElement(By.name("wd"));
        txtbox.sendKeys("Glen");
        
        WebElement btn = driver.findElement(By.id("su"));
        btn.click();
        
        driver.close();

    }

}

谷歌浏览器

 

package com.selenium.Glen;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.*;

public class chromedriver {

    private static WebDriver driver;

    public static void main(String[] args) {
        
        //如果火狐浏览器没有默认安装在C盘,需要制定其路径
        //System.setProperty("webdriver.firefox.bin", "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
      //  WebDriver driver = new FirefoxDriver();
      
            System.setProperty("webdriver.chrome.driver","C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe");
         WebDriver webDriver = new ChromeDriver();
          driver.get("http://www.baidu.com");
         driver.manage().window().maximize();
          WebElement txtbox = driver.findElement(By.name("wd"));
        txtbox.sendKeys("Glen");
        
        WebElement btn = driver.findElement(By.id("su"));
        btn.click();
         driver.close();

    }

}

 

Selenium 打开百度,简单代码

标签:app   百度   路径   http   ati   driver   baidu   pack   .exe   

原文地址:http://www.cnblogs.com/HenryLi03/p/6932999.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!