閑聊一下:
畢業(yè)后的第一份工作很重要,我2015年6月985碩士畢業(yè),7月參加工作,由于自己對(duì)職業(yè)生涯的迷茫,再加上對(duì)offer選擇錯(cuò)誤的后果(考慮太多也是錯(cuò)),導(dǎo)致自己現(xiàn)在并未從事自己一直愿意從事的自動(dòng)化測(cè)試工作,今年想換工作了,還是特別想從事自動(dòng)化測(cè)試的工作,可是目前的有一個(gè)offer也不是測(cè)試的(傷!),還有一個(gè)測(cè)試的offer在等結(jié)果,估計(jì)這兩天就能有通知(好希望能夠被錄用!!)。用我的經(jīng)歷,提醒大家,在畢業(yè)之前一定要想好自己想從事的方向,并且在選擇offer時(shí)一定毫不猶豫的選擇對(duì)自己發(fā)展有利的大公司~
現(xiàn)在就整理下自己實(shí)現(xiàn)java和selenium框架的自動(dòng)打開(kāi)網(wǎng)頁(yè)
1.準(zhǔn)備階段
安裝eclipse;以及selenium的相關(guān)jar包加載至eclipse:
2. java代碼實(shí)現(xiàn):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
</ pre >< pre name = "code" class = "java" >package javaSelenium_Test; import org.openqa.selenium.By; //打開(kāi)firefox瀏覽器的http://baidu.com網(wǎng)址 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.server.browserlaunchers.Sleeper; public class Case1 { public static void main(String[] args){ // WebDriver driver = new FirefoxDriver(); System.setProperty("webdriver.firefox.bin", "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe"); WebDriver driver = new FirefoxDriver(); driver.get("http://baidu.com"); WebElement input = driver.findElement(By.xpath(".//*[@id='kw']")); CharSequence[] cs = new CharSequence[1]; cs[0]="安居客"; input.sendKeys(cs); WebElement btn = driver.findElement(By.xpath(".//*[@id='su']")); btn.click(); // WebElement btn1 = driver.findElement(By.xpath(".//*[@id='w-75cn8k']/div/h2/a[1]")); //btn1.click(); System.out.println("Page title is:"+driver.getTitle()); //Sleep(2000); driver.close(); } } |
以上這篇java+selenium實(shí)現(xiàn)自動(dòng)化打開(kāi)頁(yè)面的方法就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持服務(wù)器之家。
原文鏈接:https://blog.csdn.net/ru_li/article/details/50969883