【发布时间】:2012-08-01 22:27:35
【问题描述】:
大家! 我遇到了以下问题: 有一些
SearchContext searchContext;
By by;
可以是 WebDriver 或 WebElement。 假设它们都已经初始化(我们不知道如何); 现在我们想用这样的 xpath 找到元素,似乎要遵循
List<WebElement> elements = searchContext.findElements(by);
但是,如果 searchContext 是 WebElement 并且
by = By.xpath("//div");
这行不通! (不会找到任何元素),因为我们需要这样做
by = By.xpath("./div");
(见Locating child nodes of WebElements in selenium) 但是,正如我所提到的,我们对 by 是如何初始化的一无所知;
所以,我的问题是:尽管存在上述问题,有没有办法正确找到元素? 我有两个变量:by 和 searchContext,我应该在 searchContext 中找到指定的元素。
【问题讨论】: