2

I am trying to send text with the option sendkeys(). This is my method case within my class page object:

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

The test is shown the error

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

Can anyone help me with this error.

3
  • The error means what it says... it timed out waiting for the element to become visible. That means that either the element (likely) will never become visible or the page is loading really slowly and didn't become visible within the timeout period. We can't say which it is because we don't have access to the page or any more information. My guess is that you've chosen an element that will never become visible, maybe because the locator matches two elements, one for desktop and one for mobile where the mobile element comes first and so matches your locator but will never show on the desktop. Commented Mar 12, 2019 at 17:47
  • 1
    A suggestion... if you have a locator that only looks for an id, use By.id(). It is better supported and faster than By.xpath(). Commented Mar 12, 2019 at 17:48
  • If I am seeing what the error says, but I wanted to know if they have any suggestions,I have already used By id, when I do the manual test I can write in the input, I can also click on it, but it does not allow me to use the sendKeys the element not visible. Commented Mar 12, 2019 at 18:22

1 Answer 1

2

The desired element is an Angular element so to invoke sendKeys() instead of visibilityOfElementLocated() you have to induce WebDriverWait for the elementToBeClickable() and you can use either of the following solutions:

  • Using 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");
    }
    
  • Using 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");
    }
    
Sign up to request clarification or add additional context in comments.

3 Comments

Is waiting for the element to be clickable instead of visible something peculiar to Angular?
@MateMrše Thumb rule, If your next step is to invoke click() or sendKeys() the only ExpectedConditions for Cross Browser is elementToBeClickable as visibility doesn't guarantees clickability
@DebanjanB, thanks very much, exactly as he told me.Thanks!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.