實際上,我想獲得一個用於頁面對象模式的@FindBy
元素。@FindBy與Arquillian石墨烯
我有2個類,第一個是我的頁面對象名爲TestPage
和第二個名爲PageSaveTest
(我的測試發生在那裏,並調用TestPage
)。
我也嘗試使用@FindBy
與xpath
和id
。
>>這是我TestPage
import java.util.List;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
public class TestPage {
// get autocomplete input
@FindBy(css = "input[id*='supplierOps_input']")
private WebElement autocompleteSupplierOps;
// getter
public WebElement getAutocompleteSupplierOps() {
return autocompleteSupplierOps;
}
}
>>這是我PageSaveTest
// How i "inject" my TestPage
@Page
TestPage testpage;
[...]
// My test
WebElement autocomplete = testpage.getAutocompleteSupplierOps();
String keys = "OP";
autocomplete.sendKeys(keys); // >>>>>>> Error throwed here !
List<WebElement> listSugg = testpage.getSuggestionsSupplierOps();
錯誤消息:
org.openqa.selenium.NoSuchElementException : Returned node was not an HTML element.
我的想法:
我覺得麻煩來自@FindBy
。但我使用this example來建立我的TestPage和我的測試和this one too。
問題:有人可以向我解釋@FindBy
如何工作,並在我的例子中使用?關於石墨烯的文檔很差。
編輯:
我已經修改我的吸氣劑TestPage(上圖),我試過id屬性值的簡單打印像
public WebElement getAutocompleteSupplierOps() {
System.out.println(">>>> "+autocompleteSupplierOps.getAttribute("id"));
return autocompleteSupplierOps;
}
但仍是同樣的錯誤,@FindBy
被打開。
Another @FindBy spec在此問題中添加。
更新:
我已經固定我的選擇,但確實存在具有像駕駛員會話probleme:
page2.getAutocompleteSupplierOps();
PAGE 1 ----------------------------------> PAGE 2
driver id:1 ----------------------------------> driver id:2
driver.showPageSource() is empty
return no element found <---------------------- driver.findElement() -> not found
我用三種不同的方式,在@FindBy
中, @Drone WebDriver
最後是什麼@Lukas Fryc
建議給我。
我已經更新了我的OP。請看看。 – e1che 2013-05-03 09:47:33