0
由於某些原因,Selenium沒有找到元素了,我得到java.lang.NullPointerException。我通過xpath獲得了一個類的定位器。當我在html中搜索xpath時,我只得到一個結果,所以它應該被創建。硒沒有找到元素
這就是元素是HTML:
<input type="text" class="form-control app-header-page-search-field ng-pristine ng-untouched ng-valid" placeholder="Nome do produto, marca ou sku:123" ng-model="vm.search" ng-model-options="{ debounce: 200 }" uib-typeahead="ngram for ngramResults in vm.getAutocompleteItems($viewValue)"
typeahead-template-url="/app/_template/typeahead-match.template.html" typeahead-popup-template-url="/app/_template/typeahead-popup.template.html" ng-enter="" typeahead-on-select="vm.autocompleteSelect($item)" typeahead-no-results="noResults" aria-autocomplete="list"
aria-expanded="false" aria-owns="typeahead-36-8683">
這是從Page類的方法:
@FindBy(xpath = "//span[text() = 'Produtos']")
@CacheLookup
private WebElement produtos;
public Produtos clickProdutos(){
wait.until(ExpectedConditions.visibilityOf(produtos));
produtos.click();
return new Produtos(driver, wait);
}
這也是我如何調用此方法在我的@Test方法中。
@Test
public void runTestCheckProdutos(){
Home home = new Home(driver, wait);
home.clickProdutos();
你從哪裏得到NPE?究竟在哪一行? 'produtos'變量是否在任何地方聲明?我在代碼中看不到聲明。 – krokodilko
我以爲你正在尋找busca元素,但點擊productos。 wait.until(ExpectedConditions.visibilityOf(busca)); busca.click(); –
我的不好,我發佈了錯誤的FindBy嘿嘿。用正確的(produtos)編輯 –