I am writing script to select and enter value in below screen in JIRA.
The 'issue type' is an 'input' element with autocomplete property:
<input type="text" autocomplete="off" role="combobox" aria-autocomplete="list" aria-haspopup="true" aria-expanded="false" class="text aui-ss-field ajs-dirty-warning-exempt" id="issuetype-field" aria-controls="issuetype-suggestions">
Right after entering value for 'input type', the rest of fields such as 'summary' grey out for a few seconds. If I try to enter value for 'summary' field right after, using following code:
myDriver.findElement(By.id("summary")).sendKeys(summary);
summary field will not be entered, rather an error "Element not found in the cache - perhaps the page has changed since it was looked up.." will happen.
HTML code for 'summary' field is:
<input type="text" value="" name="summary" id="summary" class="text long-field">
So what i want is just to wait for 'summary' input field to be enabled and then sendkey to it. I am looking for something like
ExpectedConditions.presenceOfElementLocated
but instead i want 'enabled', not presenceOfElementLocated
or visibilityOfElementLocated
. I do not want to use Thread.sleep()
either.
Any suggestions?
Selenium: Waiting Until the Element Is Visible var wait = new WebDriverWait(driver, TimeSpan. FromSeconds(20)); As you can see, we give the WebDriverWait object two parameters: the driver itself and a TimeSpan object that represents the timeout for trying to locate the element.
Wait until the element's . Displayed property is true (which is essentially what visibilityOfElementLocated is checking for). Wait until the element's . Enabled property is true (which is essentially what the elementToBeClickable is checking for).
In automation testing, wait commands direct test execution to pause for a certain length of time before moving onto the next step. This enables WebDriver to check if one or more web elements are present/visible/enriched/clickable, etc.
How about ExpectedConditions.elementToBeClickable(locator)
?
elementToBeClickable
checks if the element is enabled.
https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/support/ui/ExpectedConditions.html#elementToBeClickable-org.openqa.selenium.By-
public void waitForElementEnabled(final WebElement element) {
try {
getWait().until((ExpectedCondition<Boolean>) driver -> element.isEnabled());
} catch (Exception e) {
LOGGER.info(
e + " : " + "Timed out waiting for element: " + element);
}
}
The wait is a WebDriverWait and we want to wait until we get a true response when the WebElement is enabled. The driver is my WebDriver instance which is declared globally. If it timesout without getting a true response then I cantch the exception (so that the test will continue) and show a message informing that the operation timed out. I'm using a Lambda expression so you need to be on selenium 3.1 or higher (with guava 21)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With