本文介绍了如何实现@FindBy注释的用户类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图从中得到:

@FindBy(xpath = "//div/span/img")
public WebElement addNew;

@FindBy(xpath = "//tr[2]/td[12]")
public WebElement save;

@FindBy(xpath = "//td/div/input")
public WebElement entryIdel;

@FindBy(xpath = "//textarea")
public WebElement authorFieldel;

@FindBy(xpath = "//td[3]/div/textarea")
public WebElement titleFieldel;

@FindBy(xpath = "//div/span/img")
public Button addNew;

@FindBy(xpath = "//tr[2]/td[12]")
public Button save;

@FindBy(xpath = "//td/div/input")
public InputBox entryIdel;

@FindBy(xpath = "//textarea")
public InputBox authorFieldel;

@FindBy(xpath = "//td[3]/div/textarea")
public InputBox titleFieldel;

我之前为每个元素创建了类,但当然没有任何反应。我如何创建我的元素类,以便我可以使用它而不是WebElement?

I have previously created class for each element, but of course nothing happens. How i can create my element class so that i can use it instead of WebElement?

这里是InputBox的代码:

Here the code of InputBox at this moment:

 import org.openqa.selenium.WebElement;

  public class InputBox {

protected WebElement element;

public WebElement getElement() {
    return element;
}

public InputBox(WebElement element) {
    this.element = element;
    // TODO Auto-generated constructor stub
}

public void type(String input) {
    clearText();
    element.sendKeys(input);
}

public void clearText() {
    element.clear();
}

public boolean isEditable() {
    return element.isEnabled();
}

String getText() {
    return element.getText();
}

String getValue() {
    return element.getValue();
}

}


推荐答案

创建FieldDecorator的新实现。

Create a new implementation of FieldDecorator.

当您使用PageFactory时,您可能正在调用

When you use the PageFactory you are probably calling

 public static void initElements(ElementLocatorFactory factory, Object page)

这会成为

 public static void initElements(FieldDecorator decorator, Object page)

您的FieldDecorator的行为与DefaultFieldDecorator的行为类似,只不过将代理包装在您的自定义类型中。

Your FieldDecorator could behave similarly to the DefaultFieldDecorator except wrap the proxy in your custom type.

查看类这里

这篇关于如何实现@FindBy注释的用户类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 05:51