(二)查询
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.openqa.selenium.support.ui.ExpectedCondition; 8 import org.openqa.selenium.support.ui.WebDriverWait; 9 import org.testng.annotations.Test; 10 11 import java.util.List; 12 import java.util.concurrent.TimeUnit; 13 14 public class AutoTestTwo { 15 16 @Test 17 public void test() throws InterruptedException { 18 System.setProperty("webdriver.chrome.driver","D:/selenium-drivers/chromedriver.exe"); 19 WebDriver webDriver = new ChromeDriver(); 20 webDriver.manage().window().maximize(); 21 webDriver.get("http://xxx.xxx.xxx.xxx:xxxx/xxx"); 22 webDriver.manage().timeouts().implicitlyWait(2,TimeUnit.SECONDS); 23 //登录 24 webDriver.findElement(By.id("loginUser.id")).sendKeys("xxxxxx"); 25 webDriver.findElement(By.id("loginUser.pass")).sendKeys("xxxxxx"); 26 webDriver.findElement(By.className("submitLink")).click(); 27 webDriver.findElement(By.xpath("//*[@id=‘guard-base‘]/a")).click(); 28 webDriver.findElement(By.xpath("//*[@id=‘guard-base‘]/ul/li[1]/a")).click(); 29 webDriver.switchTo().frame("main-frame"); 30 (new WebDriverWait(webDriver,3,1)).until(new ExpectedCondition<Boolean>() { 31 @Override 32 public Boolean apply(WebDriver driver) { 33 return driver.findElement(By.id("listPager")).isDisplayed(); 34 } 35 }); 36 37 List<WebElement> btns = webDriver.findElement(By.id("listPager")).findElements(By.tagName("a")); 38 for(WebElement btn:btns ){ 39 if (btn.getText().equals("3")){ 40 btn.click(); 41 break; 42 } 43 } 44 45 (new WebDriverWait(webDriver,3)).until(new ExpectedCondition<Boolean>() { 46 @Override 47 public Boolean apply(WebDriver d) { 48 return d.findElement(By.id("newList")).isDisplayed(); 49 } 50 }); 51 List<WebElement> tables = webDriver.findElement(By.id("newList")).findElements(By.tagName("tr")); 52 tables.get(tables.size()-1).findElement(By.className("delRecord")).click(); 53 54 Thread.sleep(2000); 55 56 Actions action = new Actions(webDriver); 57 WebElement el = webDriver.findElement(By.xpath("//*[@id=‘_myConfirm‘]/div/div/div[3]/button[1]")); 58 action.moveToElement(el).click().perform(); 59 60 webDriver.quit(); 61 } 62 }
时间: 2024-11-04 01:21:06