Моя цель - создать функцию для просмотра всех фреймов, пока не будет найден хороший элемент (потому что мы не можем найти элемент, если мы не в фрейме). Эта функция должна найти и переключиться на хороший кадр и вернуть true, если элементы находятся в кадре.
private boolean findFrame(By locator) {
boolean found = false;
// for elements not into to a frame
if (isElementPresent(locator, 1))
found = true;
if (!found) {
// there are frames in the page
List<WebElement> frames = this.driver.findElements(By.xpath("//frame"));
int i = 0;
while (i < frames.size() && !found) {
WebElement frame = this.driver.findElement(By.xpath("//frame[@id = '" + frames.get(i).getAttribute("id") + "']"));
this.driver.switchTo().frame(frame);
found = findFrame(locator);
if (!found)
driver.switchTo().parentFrame();
i++;
}
}
return found;
}
Считаете ли вы, что эту функцию ревизии можно улучшить (улучшить производительность)?
Спасибо.