【发布时间】:2019-02-08 23:53:14
【问题描述】:
我尝试通过 Java Selenium 将密钥发送到输入字段。我每次都得到 NoSuchElementException。我还尝试了此解决方案中的所有内容:NoSuchElementExeption, selenium unable to locate element。提前致谢!
driver.findElement(By.xpath("//input[@class='pull-left ng-pristine ng-validng-empty ng-touched']")).sendKeys(t + Keys.ENTER);
<input class="pull-left ng-pristine ng-valid ng-empty ng-touched" ng-model="TagInputCtrl.tagInput" uib-typeahead="tagSuggestion for tagSuggestion in TagInputCtrl.getTagSuggestions($viewValue)" select-on-comma="" select-on-whitespace="" select-on-blur="" typeahead-focus-first="false" tag-select="TagInputCtrl.onEnter" tag-select-model="ngModel" sprd-max-input-length="50" ng-show="ngModel.length < TagInputCtrl.validatorOptions.tags.max" ng-focus="TagInputCtrl.focused = true" ng-blur="TagInputCtrl.focused = false" aria-autocomplete="list" aria-expanded="false" aria-owns="typeahead-4377-3960" style="" type="text"/>
【问题讨论】:
-
xpath 与当前标签不匹配。
-
抱歉输入字段错误。现在它是正确的。所以xpath是正确的。
-
如果您在页面加载(在搜索中)时将该 xpath 定位器输入到 chrome 调试器中,它会找到该元素吗?还是它可能找到多个元素?
标签: java selenium xpath css-selectors webdriver