selenium代码练习
百度搜索
package cntest.byp;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class BaiDu {
public static void main(String[]args) throws InterruptedException{
//指定火狐瀏覽器
// System.setProperty("WebDriver.firefox.bin", "火狐安裝路徑.firefox.exe,路徑加轉(zhuǎn)譯(再加個/或者寫為\)");
//打開瀏覽器,用到了web driver
//多態(tài)
WebDriver driver= new FirefoxDriver();
//最大化窗口
driver.manage().window().maximize();
//輸入網(wǎng)址
driver.get("http://www.baidu.com");
//時間等待
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
// driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
//輸入內(nèi)容,先定位元素,比如找到搜索輸入框
// WebElement element=driver.findElement(By.id("kw"));
// element.sendKeys("黏土");
//上面2行合并
driver.findElement(By.id("kw")).sendKeys("黏土");
//點擊百度一下
driver.findElement(By.id("su")).click();
//強制等待
Thread.sleep(3000);
//關(guān)閉瀏覽器
driver.close();
//關(guān)閉驅(qū)動
driver.quit();
轉(zhuǎn)載于:https://www.cnblogs.com/meteorbai/p/6979720.html
總結(jié)
以上是生活随笔為你收集整理的selenium代码练习的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 探索Oracle之数据库升级八 12
- 下一篇: 算法导论之红黑树的学习