一、代码如下
package www.gui.liulanqi;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
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.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
public class Chrome {
WebDriver driver= null;
Actions actions= null;
public static void main(String[] args) {
// TODO Auto-generated method stub
Chrome gd= new Chrome();
gd.init();
//gd.killDo();
//gd.tableProcess();
}
private void init() {
System.setProperty("webdriver.chrome.bin", "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe");
//C:Documents and SettingsAdministratorLocal SettingsApplication DataGoogleChrome
//C:Documents and SettingsAdministratorLocal SettingsApplication DataGoogleChrome
//C:Program Files (x86)GoogleChromeApplicationchrome.exe
//this.driver = new FirefoxDriver();// 启动火狐浏览器
this.driver= new ChromeDriver();
this.driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);// 元素等待时间
this.driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);// 页面加载时间
this.driver.manage().timeouts().setScriptTimeout(30, TimeUnit.SECONDS);// ajax请求
this.driver.manage().window().maximize();
// this.driver.get("https://www.baidu.com/");// 在浏览器中打开该网址
this.driver.get("http://localhost/Agileone/");
this.driver.findElement(By.id("username")).sendKeys("admin");
this.driver.findElement(By.id("password")).sendKeys("admin");
this.driver.findElement(By.id("login")).click();
this.driver.findElement(By.partialLinkText("需求提案")).click();
}
}
package www.gui.liulanqi;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
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.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.remote.DesiredCapabilities;
public class Chrome3 {
WebDriver driver= null;
Actions actions= null;
public static void main(String[] args) {
// TODO Auto-generated method stub
Chrome3 gd= new Chrome3();
gd.init();
//gd.killDo();
//gd.tableProcess();
}
private void init() {
System.setProperty("webdriver.chrome.driver", "C:\chromedriver.exe");
this.driver= new ChromeDriver();
this.driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);// 元素等待时间
this.driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);// 页面加载时间
this.driver.manage().timeouts().setScriptTimeout(30, TimeUnit.SECONDS);// ajax请求
this.driver.manage().window().maximize();
// this.driver.get("https://www.baidu.com/");// 在浏览器中打开该网址
this.driver.get("http://localhost/Agileone/");
this.driver.findElement(By.id("username")).sendKeys("admin");
this.driver.findElement(By.id("password")).sendKeys("admin");
this.driver.findElement(By.id("login")).click();
this.driver.findElement(By.partialLinkText("需求提案")).click();
}
}
chrome版本40.7
package www.woniu.gaobanben;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
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.chrome.ChromeOptions;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
public class Chrome {
WebDriver driver = null;
Actions actions = null;
public static void main(String[] args) {
// TODO Auto-generated method stub
Chrome gd = new Chrome();
gd.init();
// gd.killDo();
// gd.tableProcess();
}
private void init() {
System.setProperty("webdriver.chrome.driver", "d:/chromedriver_2.15.exe");
System.setProperty("webdriver.chrome.bin",
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe");
//C:Program Files (x86)GoogleChromeApplicationchrome.exe
// C:Users
ootAppDataLocalGoogleChromeApplicationchrome.exe
// C:Documents and SettingsAdministratorLocal SettingsApplication
// DataGoogleChrome
// C:Documents and SettingsAdministratorLocal SettingsApplication
// DataGoogleChrome
// C:Program Files (x86)GoogleChromeApplicationchrome.exe
// this.driver = new FirefoxDriver();// 启动火狐浏览器
// ChromeOptions options = new ChromeOptions();
// // 通过配置参数禁止data;的出现
// options.addArguments("--user-data-dir=C:\Users\root\AppData\Local\Google\Chrome\User Data\Default");
// //C:Users
ootAppDataLocalGoogleChromeUser DataDefault
// // 通过配置参数删除“您使用的是不受支持的命令行标记:--ignore-certificate-errors。稳定性和安全性会有所下降。”提示
// options.addArguments("--start-maximized", "allow-running-insecure-content", "--test-type");
// driver = new ChromeDriver(options);
this.driver = new ChromeDriver();
this.driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);// 元素等待时间
this.driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);// 页面加载时间
this.driver.manage().timeouts().setScriptTimeout(30, TimeUnit.SECONDS);// ajax请求
this.driver.manage().window().maximize();
//this.driver.navigate().to("www.baidu.com");
//this.driver.Navigate().GoToUrl("www.baidu.com");
this.driver.get("https://www.baidu.com/");// 在浏览器中打开该网址
this.driver.findElement(By.id("kw")).sendKeys("kao");
// this.driver.get("http://localhost/Agileone/");
// this.driver.findElement(By.id("username")).sendKeys("admin");
// this.driver.findElement(By.id("password")).sendKeys("admin");
// this.driver.findElement(By.id("login")).click();
//
// this.driver.findElement(By.partialLinkText("需求提案")).click();
}
}