HTML元素yandex qa工具硒包装器可以很好地工作,当元素在页面对象上并通过@FindBy
注释和HtmlElementLoader.populatePageObject(this, ((WebDriverBrowser)Browser.getDriver()).getWebDriver());
在页面对象构造函数中初始化时,init元素可以很好地工作
但是如果页面内容是动态变化的,例如,我想在没有@FindBy湖的情况下创建HtmlElement:
public static void openNavigator(String navigatorName) {
String navigatorPath = String.format(MENU_OBJ_XPATH_PATTERN, navigatorItemMenuName);
Element navigatorMenu = new Element(By.xpath(navigatorXpath));
navigatorMenu.waitForVisible();
}
在这种情况下,元素构造函数看起来像
public Element(By locator) {
this.locator = locator;
}
错误:no such element: Unable to locate element
即使我直接尝试初始化元素
HtmlElementLoader.createHtmlElement(Element.class, Browser.getBrowser().getWebDriver().findElement(By.xpath("//td[contains(text(),'Navigator')]")))
错误
no such element: Unable to locate element: {"method":"xpath","selector":"//td[contains(@id,'cnt-start')]//*[contains(text(),'Navigator')]"}
(Session info: chrome=68.0.3440.106)
(Driver info: chromedriver=2.41.578737 (49da6702b16031c40d63e5618de03a32ff6c197e),platform=Windows NT 10.0.16299 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
是否可以像这样使用HTML元素包装器?
答案 0 :(得分:0)
尝试
WebDriverWait wait = new WebDriverWait(webDriver, timeoutInSeconds);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(navigatorXpath)));
答案 1 :(得分:0)
没有足够的上下文来提供最佳解决方案,但这是一个:将项目定义为元素数组。然后,您可以迭代查找特定的对象:
Component level state