我正在使用 selenium pagefactory,并引入了一个注释 @Name(Description = "Username"),我将其用于所有 WebElement。稍后我需要在我的自定义方法中找到 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 的类名,并将字段名作为字符串 "username" 提供,以检索注释值。
我希望能够通过仅向我的 click(WebElement element) 方法提供我的 WebElement 而没有其他对象来检索注释值。