如何寻找网站建设需求客户,深圳网站建设的价格,wordpress 显示代码,深圳58同城招聘网在eclipse中新建一个项目baidutest#xff1b;再在src文件夹中新建一个包com.baidutest.homework#xff1b;再在包中新建一个java类baidusetting#xff0c;并设置为静态类#xff1b;最后在项目中新建一个lib文件夹#xff0c;将selenium的所有架包拷贝到lib文件夹中再在src文件夹中新建一个包com.baidutest.homework再在包中新建一个java类baidusetting并设置为静态类最后在项目中新建一个lib文件夹将selenium的所有架包拷贝到lib文件夹中并设置选中项目baidutest右键选择Bulid Path-Configure Bulid Path将lib中的所有架包添加到Libraries中。至此selenium包配置完毕。有什么疑惑可以参照百度经验eclipsejava添加外部架包现在要做的是打开百度页面点击设置中的搜索设置修改搜索设置中的选项。代码如下package com.baidutest.homework;import org.openqa.selenium.support.ui.Select;import org.openqa.selenium.chrome.ChromeDriver;import org.openqa.selenium.interactions.Actions;import org.openqa.selenium.Alert;import org.openqa.selenium.By;import org.openqa.selenium.WebDriver;import org.openqa.selenium.WebElement;import org.openqa.selenium.By.ById;import java.util.*;//保证List使用正确public class baidusetting {public static void main(String[] args) throws InterruptedException {// TODO Auto-generated method stub//告诉计算机浏览器驱动在哪里System.setProperty(webdriver.chrome.driver,C:\\Users\\Dell\\Downloads\\chromedriver.exe);WebDriver drivernew ChromeDriver();//访问百度网址driver.get(https://www.baidu.com/);driver.manage().window().maximize();//窗口最大化//模拟将鼠标放置在搜索上Actions actionnew Actions(driver);action.moveToElement(driver.findElement(By.xpath(//*[id\u1\]/a[8]))).perform();Thread.sleep(2000);driver.findElement(By.linkText(搜索设置)).click();Thread.sleep(2000);//此时有两个页面一个是百度页面一个是搜索设置页面String handle_baidudriver.getWindowHandle();System.out.println(当前页面的标题为driver.getTitle());//打印目前页面的标题//如果当前的窗口句柄数不为1则执行切换窗口if (driver.getWindowHandles().size()!1) {//循环遍历找到登录页面的句柄并切换到登录页面for (String handles:driver.getWindowHandles()){if (handles.equals(handle_baidu)) {continue;}driver.switchTo().window(handles);//切换到登录页面}System.out.println(切换之后页面的标题为driver.getTitle());//打印目前页面的标题}//搜索框提示if (driver.findElement(By.id(s1_2)).isSelected()false) {driver.findElement(By.id(s1_2)).click();}Thread.sleep(1000);//搜索语言范围List radiosdriver.findElements(By.name(SL));if (radios.get(1).isSelected()false) {radios.get(1).click();}Thread.sleep(1000);//搜索结果显示条数Select selectnew Select(driver.findElement(ById.cssSelector(select[nameNR])));select.selectByIndex(1);//选择每页显示20条Thread.sleep(2000);//实时预测功能Select select_yucenew Select(driver.findElement(ById.cssSelector(select[nameissw1])));select_yuce.selectByVisibleText(关闭);//选择关闭实时预测功能Thread.sleep(1000);//搜索历史记录if (driver.findElement(By.id(sh_1)).isSelected()false) {driver.findElement(By.id(sh_1)).click();}Thread.sleep(1000);//通栏浏览模式if (driver.findElement(By.id(stb_2)).isSelected()false) {driver.findElement(By.id(stb_2)).click();}Thread.sleep(1000);driver.findElement(By.xpath(//*[id\gxszButton\]/a[1])).click();Thread.sleep(2000);//停顿2秒//处理弹出框Alert alertdriver.switchTo().alert();alert.accept();//. accept() 相当于点击它的确认. dismiss() 相当于点击取消或者叉掉对话框Thread.sleep(3000);//停顿3秒driver.quit();}}