package jkcs;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
public class jdcs
{
public static void main(String[] args) throws InterruptedException
{
System.setProperty("webdriver.chrome.bin","C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe"); //设置安装路径,防止系统找不到
WebDriver driver = new FirefoxDriver(); //初始化FireFox浏览器实例,并打开浏览器
driver.manage().window().maximize(); //最大化窗口
driver.navigate().to("http://www.baidu.com");
Thread.sleep(5000);
driver.findElement(By.id("kw")).sendKeys("china"); //文本框里输入
Thread.sleep(5000);
Actions sj = new Actions(driver);
sj.click(driver.findElement(By.id("su"))).perform(); //模拟鼠标左击
Thread.sleep(8000);
driver.quit();
}
}
java工作复习——4大时间等待——强制等待(Thread.sleep(5000);)
最新推荐文章于 2025-04-21 16:04:25 发布
本文介绍如何使用Selenium WebDriver自动化测试框架,通过Firefox浏览器实现对百度搜索引擎的自动化操作,包括页面打开、搜索框输入、点击搜索按钮等流程。
753

被折叠的 条评论
为什么被折叠?



