日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

selenium代码练习

發布時間:2025/7/14 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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,路徑加轉譯(再加個/或者寫為\)");

//打開瀏覽器,用到了web driver
//多態
WebDriver driver= new FirefoxDriver();
//最大化窗口
driver.manage().window().maximize();

//輸入網址
driver.get("http://www.baidu.com");
//時間等待
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
// driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
//輸入內容,先定位元素,比如找到搜索輸入框
// 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);


//關閉瀏覽器
driver.close();
//關閉驅動
driver.quit();

轉載于:https://www.cnblogs.com/meteorbai/p/6979720.html

總結

以上是生活随笔為你收集整理的selenium代码练习的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。