• 浏览器启动__chrome浏览器


    一、代码如下

    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();
    
    	}
    
    }
    
  • 相关阅读:
    windows下安装mysql-5.7.11-winx64
    memset库函数
    [转]全面解析《嵌入式程序员应该知道的16个问题》
    Cent OS 7 下 Redis 5.0.5 安装与配置
    SVN+TortoiseSVN的Windows版安装和配置
    工具和环境--目录(随时更新)
    Linux安装和配置Nodejs和NPM
    Windows10命令提示符窗口大小导致执行效率不同问题
    Windows安装Nodejs和npm以及创建项目
    WebStorm 2019.3.2安装与配置
  • 原文地址:https://www.cnblogs.com/wujianbo123/p/7705773.html
Copyright © 2020-2023  润新知