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)编辑 –