Python's
selenium.webdriver.support.expected_conditions.element_to_be_clickable
does not have an equivalent condition in this context. However, upon examining the source code of that condition, it appears to perform two checks:
Checking if the element is visible.
Verifying if the element is enabled.
In order to achieve a similar functionality, one can wait for both of these conditions to be met. The provided code snippet demonstrates how this can be implemented. It involves making an element invisible and disabled initially, setting timeouts to make it visible and enabled, and then waiting for the desired conditions.
var webdriver = require('selenium-webdriver');
var driver = new webdriver.Builder().
withCapabilities(webdriver.Capabilities.chrome()).
build();
driver.get('http://www.google.com');
// The following script showcases testing the wait operation. Initially, we make the element invisible
// and disable it. Subsequently, we set timeouts to ensure its visibility and enablement.
driver.executeScript("\
var q = document.getElementsByName('q')[0];\
q.style.display = 'none';\
q.disabled = true;\
setTimeout(function () {\
q.style.display = '';\
}, 2000);\
setTimeout(function () {\
q.disabled = false;\
}, 3000);\
");
driver.findElement(webdriver.By.name('q')).then(function (element) {
driver.wait(function () {
return element.isDisplayed().then(function (displayed) {
if (!displayed)
return false;
return element.isEnabled();
});
});
element.sendKeys('webdriver');
});
driver.findElement(webdriver.By.name('btnG')).click();
driver.wait(function() {
return driver.getTitle().then(function(title) {
return title === 'webdriver - Google Search';
});
}, 1000);
driver.quit();
The structure of the code may appear unfamiliar due to the asynchronous nature of promises. While promises are not inherently complex, they might require some time for adaptation especially for those accustomed to working with Python.