2014-12-27 69 views
2

如何在HtmlElement中創建自己的TypifiedElement?如何創建自己的TypifiedElement

我創建自己的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) 

哪裏是我的錯以及如何糾正init我自己的TypifiedElement? 謝謝

回答

1

從堆棧跟蹤中,它可能是您創建YesNoRadio實例的類位於不同的包中。因此,你需要聲明後者的構造函數public

public YesNoRadio(WebElement wrappedElement) { 
+0

所有作品,當我改變構造函數'public' – Funker 2014-12-27 22:47:06

+0

謝謝你這個答案如預期,這是100%正確的 - 你應該在你的元素公共構造。 – artkoshelev 2014-12-29 09:26:22