- AndroidDriver driver = new AndroidDriver();
- driver.get("http://m.taobao.com");
- WebElement inputBox = driver.findElement(By.id("J_SKey"));
- inputBox.sendKeys("1");
- new WebDriverWait(driver, 10).until (new ExpectedCondition<Boolean>() {
- @Override
- public Boolean apply(WebDriver driver) {
- Boolean result = false;
- try {
- driver.findElement(By.xpath("//div[@class=‘suggest‘]//li"));
- result = true;
- } catch(Exception e){
- }
- return result;
- }
- });
- assertTrue(driver.findElement(By.xpath("//div[@class=‘suggest‘]//li")).getText().contains("1"));
WebDriverWait(driver, 10)10秒内每隔500毫秒扫描1次页面变化,当出现指定的元素后结束。
时间: 2024-10-14 21:07:27