(三)删除
1 package test; 2 3 4 import org.openqa.selenium.*; 5 import org.openqa.selenium.chrome.ChromeDriver; 6 import org.openqa.selenium.interactions.Actions; 7 import org.testng.annotations.Test; 8 import java.util.concurrent.TimeUnit; 9 10 11 public class AutoTestThree { 12 @Test 13 public void test() throws InterruptedException{ 14 System.setProperty("webdriver.chrome.driver","D:/selenium-drivers/chromedriver.exe"); 15 WebDriver webDriver = new ChromeDriver(); 16 webDriver.manage().window().maximize(); 17 webDriver.get("http://xxx.xxx.xxx.xxx:xxxx/xxx"); 18 webDriver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS); 19 //登录 20 webDriver.findElement(By.id("loginUser.id")).sendKeys("xxxxxx"); 21 webDriver.findElement(By.id("loginUser.pass")).sendKeys("xxxxxx"); 22 webDriver.findElement(By.className("submitLink")).click(); 23 webDriver.findElement(By.xpath("//*[@id=‘guard-base‘]/a")).click(); 24 webDriver.findElement(By.xpath("//*[@id=‘guard-base‘]/ul/li[1]/a")).click(); 25 webDriver.switchTo().frame("main-frame"); 26 //请输入职业打假人姓名... 27 webDriver.findElement(By.xpath("//*[@id=‘searchObj‘]")).sendKeys("test"); 28 Thread.sleep(2000); 29 //选择行业 30 webDriver.findElement(By.xpath("//*[@id=‘industrySpan-myselect-tree‘]")).click(); 31 WebElement el1 = webDriver.findElement(By.xpath("//*[@id=‘industrySpan-myselect-tree‘]/div/ul/li[1]/div/span[1]")); 32 WebElement el2 = webDriver.findElement(By.xpath("//*[@id=‘industrySpan-myselect-tree‘]/div/ul/li[1]/ul/li[1]/div/span[2]")); 33 WebElement el3 = webDriver.findElement(By.xpath("//*[@id=‘industrySpan-myselect-tree‘]/div/ul/li[1]/ul/li[1]/ul/li[1]/div/span[3]")); 34 WebElement el4 = webDriver.findElement(By.xpath("//*[@id=‘industrySpan-myselect-tree‘]/div/ul/li[1]/ul/li[1]/ul/li[1]/ul/li[1]/div/span[4]")); 35 Actions action = new Actions(webDriver); 36 37 action.moveToElement(el1).click().perform(); 38 action.moveToElement(el2).click().perform(); 39 action.moveToElement(el3).click().perform(); 40 action.moveToElement(el4).click().perform(); 41 42 43 Thread.sleep(1000); 44 45 webDriver.findElement(By.cssSelector(".search")).findElement(By.cssSelector(".search_icon")).click(); 46 Thread.sleep(1500); 47 webDriver.findElement(By.xpath("//button[@class=‘search‘and text()=‘重置‘]")).click(); 48 49 50 51 Thread.sleep(1000); 52 53 webDriver.quit(); 54 } 55 }
时间: 2024-10-05 21:52:58