【发布时间】:2019-08-23 13:57:53
【问题描述】:
我正在使用 selenium pagefactory,并引入了注释 @Name(Description = "Username"),我将其用于所有 WebElements。 稍后我需要在我的自定义方法中找到 Description 的值,以便进行报告,例如:
public static void click(WebElement element) throws Throwable {
try {
element.click();
} catch(ElementNotInteractableException E1) {
throw new UnableToInteractWithElementException("Unable To Interact With " + WebElement Descriptionn);
}
}
我的@Name注解界面和pagefactory是这样的:
名称接口
@Target({ElementType.FIELD, ElementType.TYPE,ElementType.CONSTRUCTOR})
public @interface Name {
String Description() default "";
}
@Name(Description = "Username")
@FindBy(id="txtLoginID")
public WebElement username;
我在使用反射时遇到的问题是需要定义 pagefactory 的类名,并提供字段名作为字符串“用户名”,以检索注释值。
我希望能够通过仅向我的 click(WebElement 元素) 方法提供我的 WebElement 而没有其他对象来检索注释值。
【问题讨论】:
-
我认为在以
WebElement为参数的方法中是不可能的。您还必须传递整个页面对象。public static void click(Class<? extends PageObject> poClass, WebElement element)。这可以接受吗?
标签: java selenium selenium-webdriver reflection page-factory