【发布时间】:2014-10-20 22:03:41
【问题描述】:
这是我通常为查找名称为“电子邮件”的元素而写的内容
WebElement emailInput = (new WebDriverWait(driver, 10))
.until(ExpectedConditions.presenceOfElementLocated(By
.name("email")));
如果有如下所示的元素模态体怎么办
WebElement modalBody = enrollForm.findElement(By
.className("modal-body"));
现在,如果我要在另一个 WebElement 中找到一个特定的 WebElement,就像...
WebElement a = driver.findElement(By.id("KeepSmiling");
WebElement b = a.findElement(By.className("ChocolatesMakeMeSizzle");
这里b 是a 中的一个元素。由于还有许多其他带有 className 的 div -> ChocolatesMakeMeSizzle
我希望做同样的事情,但使用WebDriverWait。我使用Thread.sleep(xx) 避免了这个问题,但它是一个非常糟糕的方法。
这是我尝试过的(但我意识到我试图减慢 webElement 的速度,这是没有意义的)。
WebElement emailInput = (new WebDriverWait(modalBody, 10))
.until(ExpectedConditions.presenceOfElementLocated(By
.name("email")));
任何提示如何实现这一点?
忏悔:老实说,我一直在避免这种方法并使用 Thread.sleep(xx)。
我能够使用 xpath 并找到方法,但我希望能回答我的问题! :)
【问题讨论】:
-
我们可以帮助您解决问题中包含一些 html 的 xpath。