org.openqa.selenium.TimeoutException:

我正在尝试使用选项发送文本。这是我的类页面对象中的方法案例:sendkeys()


public void setEntityName() {

    internalWait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id=\"entity_name\"]")));

    entityName.clear();

    entityName.sendKeys("TEST");

}

网页:


 <input id="entity_name" name="entity_name" type="text" ng-model="entityData.name" ng-disabled="false" placeholder="Type Enity Name" data-maxlength="20" data-smart-validate-input="" data-required="" class="ng-pristine ng-invalid ng-invalid-required ng-valid-maxlength ng-touched">

测试显示错误


org.openqa.selenium.TimeoutException: Expected condition failed: waiting for visibility of element located by By.xpath: //*[@id="entity_name"] 

任何人都可以帮助我解决此错误。


慕村225694
浏览 407回答 1
1回答

临摹微笑

所需的元素是一个 Angular 元素,因此要调用而不是您必须诱导 WebDriverWait for 和 您可以使用以下任一解决方案:sendKeys()visibilityOfElementLocated()elementToBeClickable()用:cssSelectorpublic void setEntityName() {&nbsp; &nbsp; WebElement entityName = new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("input.ng-pristine.ng-invalid.ng-invalid-required.ng-valid-maxlength.ng-touched#entity_name[ng-model='entityData.name']")));&nbsp; &nbsp; entityName.clear();&nbsp; &nbsp; entityName.sendKeys("TEST");}用:xpathpublic void setEntityName() {&nbsp; &nbsp; WebElement entityName = new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@class='ng-pristine ng-invalid ng-invalid-required ng-valid-maxlength ng-touched' and @id='entity_name'][@ng-model='entityData.name']")));&nbsp; &nbsp; entityName.clear();&nbsp; &nbsp; entityName.sendKeys("TEST");}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java