如何点击李标签的选项
答
我用selenium-webdriver,junit检查过。下面的代码对我来说工作得很好。检查这解决了你。
@Before
public void setUp() throws Exception {
driver = new FirefoxDriver();
driver.manage().window().maximize();
baseUrl = "http://www.yelp.com/";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
@Test
public void testYelpRest() throws Exception {
driver.get(baseUrl + "");
driver.findElement(By.id("find_desc")).clear();
driver.findElement(By.id("find_desc")).sendKeys("Restaurants");
driver.findElement(By.id("find_desc")).sendKeys(Keys.DOWN);
driver.findElement(By.id("find_desc")).sendKeys(Keys.ENTER);
for (int second = 0;; second++) {
if (second >= 60) fail("timeout");
try { if (isElementPresent(By.xpath("//span[@class='pagination-results-window']"))) break; } catch (Exception e) {}
Thread.sleep(1000);
}
}
@After
public void tearDown() throws Exception {
driver.quit();
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {
fail(verificationErrorString);
}
}
答
你可以试试下面的代码,我敢肯定,这将工作.. :)
public class Yelp_dropdown { public static void main(String[] args) { WebDriver driver=new FirefoxDriver(); driver.get("http://www.yelp.com/"); WebDriverWait w= new WebDriverWait(driver,5); driver.findElement(By.xpath(".//*[@id='find_desc']")).click(); w.until(ExpectedConditions.elementToBeClickable(By.xpath(".//*[@class='suggestion-detail suggestion-name' and contains (text(), 'Restaurants')]"))).click();
请分享您的代码和HTML – Guy
你遇到了什么问题?你有问题吗?请明确点。 – Martin