2

如何创建自己的 TypifiedElement 以在 HtmlElement 中使用它?

我创建了自己的 CustomElement

 public class YesNoRadio extends TypifiedElement {

     protected YesNoRadio(WebElement wrappedElement) {
        super(wrappedElement);
     }

 .... // some other methods here

 }

并尝试使用它,但在初始化元素时在我的基本页面上出现异常

 PageFactory.initElements(new HtmlElementDecorator(driver), this);

我的例外

ru.yandex.qatools.htmlelements.exceptions.HtmlElementsException: java.lang.NoSuchMethodException: No such accessible constructor on object: com.mycompany.testing.htmlelements.company.element.YesNoRadio
        at ru.yandex.qatools.htmlelements.loader.decorator.HtmlElementFactory.createTypifiedElementInstance(HtmlElementFactory.java:51)
        at ru.yandex.qatools.htmlelements.loader.decorator.HtmlElementDecorator.decorateTypifiedElement(HtmlElementDecorator.java:102)
        at ru.yandex.qatools.htmlelements.loader.decorator.HtmlElementDecorator.decorate(HtmlElementDecorator.java:66)
        at org.openqa.selenium.support.PageFactory.proxyFields(PageFactory.java:115)
        at org.openqa.selenium.support.PageFactory.initElements(PageFactory.java:107)
        at ru.yandex.qatools.htmlelements.loader.decorator.HtmlElementDecorator.decorateHtmlElement(HtmlElementDecorator.java:115)
        at ru.yandex.qatools.htmlelements.loader.decorator.HtmlElementDecorator.decorate(HtmlElementDecorator.java:70)
        at org.openqa.selenium.support.PageFactory.proxyFields(PageFactory.java:115)
        at org.openqa.selenium.support.PageFactory.initElements(PageFactory.java:107)
        at com.mycompany.testing.cds.PageBase.<init>(PageBase.java:46)

我的错误在哪里以及如何纠正我自己的 TypifiedElement?谢谢

4

1 回答 1

1

从堆栈跟踪中,您创建实例的类可能YesNoRadio位于不同的包中。因此,您需要将后者的构造函数声明为public

public YesNoRadio(WebElement wrappedElement) {
于 2014-12-27T18:51:03.000 回答