如何创建自己的TypifiedElement

时间:2014-12-27 18:44:58

标签: java selenium webdriver htmlelements

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

我创建了自己的CustomElement

 public class YesNoRadio extends TypifiedElement {

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

 .... // some other methods here

 }

尝试使用它但在init页面上的基本页面上出现异常

 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)

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

1 个答案:

答案 0 :(得分:1)

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

public YesNoRadio(WebElement wrappedElement) {