The code I am using to run the automated test for google search is below.
const webdriver = require('selenium-webdriver'),
By = webdriver.By,
until = webdriver.until;
const driver = new webdriver.Builder()
.forBrowser('chrome')
.build();
driver.get('http://www.google.com');
driver.findElement(By.name('q')).sendKeys('webdriver');
driver.sleep(10000).then(function() {
driver.findElement(By.name('q')).sendKeys(webdriver.Key.TAB);
});
driver.findElement(By.name('btnK')).click();
driver.sleep(20000).then(function() {
driver.getTitle().then(function(title) {
if(title === 'webdriver - Google Search') {
console.log('Test passed');
} else {
console.log('Test failed');
}
driver.quit();
});
});
and it is throwing an error which says that element is not interactable. I have added extra time delays for loading page successfully.
(node:32241) UnhandledPromiseRejectionWarning: ElementNotInteractableError: element not interactable
CodePudding user response:
element not interactable is telling you that the element you are trying to click on - is just not clickable.
You have 2 ways to overcome this:
Find the child element of the element you are trying to click on or its parent element.
Force the element to be clicked by injecting JavaScript into it:
JavascriptExecutor jse = (JavascriptExecutor)driver; jse.executeScript("document.getElementsByName ('btnK')[0].click();");
CodePudding user response:
You need to make a couple of adjustments as follows:
Remove the first occurance of
findElement(By.name('q'))
as you are already using the line of code later.Modify the second occurance of
findElement(By.name('q'))
to send the text andKey.RETURN
Remove the line
findElement(By.name('btnK'))
as you are already using the line of code later.Your effective line of code will be:
const driver = new webdriver.Builder() .forBrowser('chrome') .build(); driver.get('http://www.google.com'); driver.sleep(10000).then(function() { driver.findElement(By.name('q')).sendKeys('webdriver' Key.RETURN); }); driver.sleep(20000).then(function() { driver.getTitle().then(function(title) { if(title === 'webdriver - Google Search') { console.log('Test passed'); } else { console.log('Test failed'); } driver.quit(); }); });