Java+selenium百度搜索
2021/12/28 11:08:10
本文主要是介绍Java+selenium百度搜索,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
打开百度并搜索
package test; import java.util.Iterator; import java.util.List; import java.util.Set; import java.util.concurrent.TimeUnit; import org.openqa.selenium.Alert; import org.openqa.selenium.By; import org.openqa.selenium.Cookie; import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.interactions.Actions; import org.openqa.selenium.support.ui.Select; public class Test1 { public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "D:\\driver\\chromedriver.exe"); // D:\\driver是chromedriver服务地址 WebDriver driver = new ChromeDriver(); // 新建一个WebDriver 的对象,但是new 的是谷歌的驱动 String url = "http://www.baidu.com"; driver.get(url); // 打开指定的网站 driver.findElement(By.id("kw")).sendKeys(new String[] { "setProperty" }); // 找到kw元素的id,然后输入hello //打开百度F12 ![根据图片点击找到搜索框对应的ID](https://www.www.zyiz.net/i/ll/?i=5720b5f1d2b347c687e4fef2dc79fe75.png?,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAc2ltcGxlIOKYgO-4jyBzbg==,size_20,color_FFFFFF,t_70,g_se,x_16) driver.findElement(By.id("su")).click(); // 点击按扭 //上述同样方法找到搜索按钮的ID // driver.quit();// 退出浏览器 /** * dr.quit()和dr.close()都可以退出浏览器,简单的说一下两者的区别:第一个close, * 如果打开了多个页面是关不干净的,它只关闭当前的一个页面。第二个quit, * 是退出了所有Webdriver所有的窗口,退的非常干净,所以推荐使用quit最为一个case退出的方法。 */ } }
这篇关于Java+selenium百度搜索的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-31全网首发第二弹!软考2024年5月《软件设计师》真题+解析+答案!(11-20题)
- 2024-05-31全网首发!软考2024年5月《软件设计师》真题+解析+答案!(21-30题)
- 2024-05-30【Java】百万数据excel导出功能如何实现
- 2024-05-30我们小公司,哪像华为一样,用得上IPD(集成产品开发)?
- 2024-05-30java excel上传--poi
- 2024-05-30安装笔记本应用商店的pycharm,再安排pandas等模块,说是没有打包工具?
- 2024-05-29java11新特性
- 2024-05-29哪些无用敏捷指标正在破坏敏捷转型?
- 2024-05-29鸿蒙原生应用再新丁!新华社 入局鸿蒙
- 2024-05-29设计模式 之 迭代器模式(Iterator)