gpt4 book ai didi

java - org.openqa.selenium.TimeoutException : Expected condition failed: waiting for visibility of element located by By. xpath:

转载 作者:行者123 更新时间:2023-11-30 01:53:59 25 4
gpt4 key购买 nike

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

public void setEntityName() {
internalWait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id=\"entity_name\"]")));
entityName.clear();
entityName.sendKeys("TEST");
}

HTML:

 <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"] 

谁能帮我解决这个错误。

最佳答案

所需的元素是 Angular因此,要调用 sendKeys() 而不是 visibilityOfElementLocated(),您必须为 elementToBeClickable() 引发 WebDriverWait您可以使用以下任一解决方案:

  • 使用cssSelector:

    public void setEntityName() {
    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']")));
    entityName.clear();
    entityName.sendKeys("TEST");
    }
  • 使用xpath:

    public void setEntityName() {
    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']")));
    entityName.clear();
    entityName.sendKeys("TEST");
    }

关于java - org.openqa.selenium.TimeoutException : Expected condition failed: waiting for visibility of element located by By. xpath:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55126362/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com