试题
满分答案
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import java.util.Set;
import org.openqa.selenium.By;
public class Example {
// Mooctest Selenium Example
// <!> Check if selenium-standalone.jar is added to build path.
public static void test(WebDriver driver)throws InterruptedException {
// TODO Test script
// eg:driver.get("https://www.baidu.com/")
// eg:driver.findElement(By.id("wd"));
//测试网址:https://nj.zu.anjuke.com/
driver.get("https://nj.zu.anjuke.com/");
Thread.sleep(1000);
//1. 打开安居客网页版,点击租房
driver.findElement(By.xpath("/html/body/div[2]/div/ul/li[4]/a")).click();
Thread.sleep(1000);
//2. 地址选择“南京”
driver.findElement(By.xpath("//*[@id='switch_apf_id_5']/i")).click();
Thread.sleep(1000);
driver.findElement(By.xpath("//*[@id=\"city_list\"]/dl[2]/dd/a[4]")).click();
Thread.sleep(1000);
//3. 点击“地铁找房”
driver.findElement(By.xpath("/html/body/div[4]/ul/li[2]/a")).click();
Thread.sleep(1000);
//4. 选择“2 号线”
driver.findElement(By.xpath("/html/body/div[5]/div[2]/div[1]/span[2]/div/a[3]")).click();
Thread.sleep(1000);
//5. 选择“马群”
driver.findElement(By.xpath("/html/body/div[5]/div[2]/div[1]/span[2]/div/div/a[20]")).click();
Thread.sleep(1000);
//6. 设置租金为 5000-8000 元,并点击确定
driver.findElement(By.xpath("//*[@id=\"from-price\"]")).sendKeys("5000");
Thread.sleep(1000);
driver.findElement(By.xpath("//*[@id=\"to-price\"]")).sendKeys("8000");
Thread.sleep(1000);
driver.findElement(By.xpath("//*[@id=\"pricerange_search\"]")).click();
Thread.sleep(1000);
//7. 选择“整租”
driver.findElement(By.xpath("/html/body/div[5]/div[2]/div[4]/span[2]/a[2]")).click();
Thread.sleep(1000);
//8. 房屋类型选择“普通住宅”
driver.findElement(By.xpath("//*[@id=\"condmenu\"]/ul/li[2]/a")).click();
Thread.sleep(1000);
driver.findElement(By.xpath("//*[@id=\"condmenu\"]/ul/li[2]/ul/li[2]/a")).click();
Thread.sleep(1000);
//9. 在搜索框中搜索“经天路”,并点击“搜索”
driver.findElement(By.xpath("//*[@id=\"search-rent\"]")).click();
Thread.sleep(1000);
driver.findElement(By.xpath("//*[@id=\"search-rent\"]")).sendKeys("经天路");
Thread.sleep(1000);
driver.findElement(By.xpath("//*[@id=\"search-button\"]")).click();
Thread.sleep(1000);
//10. 选择“视频看房”
driver.findElement(By.xpath("//*[@id=\"list-content\"]/div[1]/a[2]")).click();
Thread.sleep(1000);
//11. 依次点击“租金”、“最新”排序进行查看
driver.findElement(By.xpath("//*[@id=\"list-content\"]/div[2]/div/a[2]")).click();
Thread.sleep(1000);
driver.findElement(By.xpath("//*[@id=\"list-content\"]/div[2]/div/a[3]")).click();
Thread.sleep(1000);
//12. 点击第一个搜索出来的房源进行查看
driver.findElement(By.xpath("//*[@id=\"list-content\"]/div[3]")).click();
Thread.sleep(2000);
}
public static void main(String[] args) {
// Run main function to test your script.
WebDriver driver = new ChromeDriver();
try { test(driver); }
catch(Exception e) { e.printStackTrace(); }
finally { driver.quit(); }
}
}
写于2021年10月29日20:29
如果这篇文章对你帮助很大,麻烦帮忙,点下友情链接: 鱼儿项目网(直接点这里),进去之后切换几个页面,停留几十秒。感激不尽。本站采集全网自媒体,网赚类,电商营销课程。里面有一些免费项目大家也可以看看