1
driver.FindElement(By.Id("UserName")).SendKeys("test");
driver.FindElement(By.Id("Password")).SendKeys("test123");       
driver.FindElement(By.XPath("//*[@id="btnSubmit"]")).Click();

Also I'm using ImplicitWait command, thread and still facing the issue

2 Answers 2

1

ElementNotInteractableException: Element is not reachable by keyboard

Element is not reachable by keyboard in plain words means that the element can’t be reached using the keyboard, which means you won't physically interact with it even.

Reason

There can be multiple reasons behind the error Element is not reachable by keyboard which can be either of the following:

The element is hidden as modern JavaScript-centric UI styles always keep the ugly raw HTML input field hidden. The hidden attribute could have been implemented through either of the following ways: A temporary overlay of some other element over the desired element. A permanent overlay of some other element over the desired element. Presence of attributes e.g. class="ng-hide", style="display: none", etc As per best practices while sending character sequence, you must not attempt to invoke click() or sendKeys() on any

or tag, instead invoke click() on the desired tag following the Official locator strategies for the webdriver. Solution

There are different approaches to address this issue.

Incase of temporary overlay use WebDriverWait inconjunction with ExpectedConditions for the desired element to be visible/clickable as follows:

import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.support.ui.ExpectedConditions;

new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.XPath("//*[@id="btnSubmit"]"))).click();

In case of permanent overlay use executeScript() method from JavascriptExecutor interface as follows:

import org.openqa.selenium.JavascriptExecutor;

WebElement myElement = driver.findElement(By.XPath("//*[@id="btnSubmit"]"));
String js = "arguments[0].setAttribute('value','"+inputText+"')"
((JavascriptExecutor) driver).executeScript(js, myElement);
0

While working in qa company, I have experienced this problem in many automation projects. There are multiple solutions to handle this blocker -

Solution 1 - Use Javascript Executor:

driver.FindElement(By.Id("UserName")).SendKeys("test");
driver.FindElement(By.Id("Password")).SendKeys("test123");       
// driver.FindElement(By.XPath("//*[@id="btnSubmit"]")).Click();
 
IWebElement element = driver.findElement(By.XPath("//*[@id="btnSubmit"]"));
IJavaScriptExecutor JsExecutor = (IJavaScriptExecutor)driver;
JsExecutor.ExecuteScript("arguments[0].click();", element);

Solution 2 - Using Keyboard Events:

driver.FindElement(By.Id("UserName")).SendKeys("test");
driver.FindElement(By.Id("Password")).SendKeys("test123");       
// driver.FindElement(By.XPath("//*[@id="btnSubmit"]")).Click();

driver.findElement(By.XPath("//*[@id="btnSubmit"]")).sendKeys(Keys.Enter);

Solution 3 - Using Action class:

driver.FindElement(By.Id("UserName")).SendKeys("test");
driver.FindElement(By.Id("Password")).SendKeys("test123");       
// driver.FindElement(By.XPath("//*[@id="btnSubmit"]")).Click();

IWebElement element = driver.FindElement(By.XPath("//*[@id="btnSubmit"]"));          
Actions builder = new Actions(driver);
builder.MoveToElement(element).Click().Perform();

Solution 4 - By Double Click the Submit button:

driver.FindElement(By.Id("UserName")).SendKeys("test");
driver.FindElement(By.Id("Password")).SendKeys("test123");       
// driver.FindElement(By.XPath("//*[@id="btnSubmit"]")).Click();

IWebElement element = driver.FindElement(By.XPath("//*[@id="btnSubmit"]"));          
Actions builder = new Actions(driver);
builder.MoveToElement(element).DoubleClick().Perform();

Solution 5 - Using Co-ordinates [Least Preferred]:

driver.FindElement(By.Id("UserName")).SendKeys("test");
driver.FindElement(By.Id("Password")).SendKeys("test123");       
// driver.FindElement(By.XPath("//*[@id="btnSubmit"]")).Click();

IWebElement element = driver.FindElement(By.XPath("//*[@id="btnSubmit"]"));          
Actions builder = new Actions(driver);
builder.move_by_offset(X coordinates, Y coordinates).click().perform()

where 'X' & 'Y' coordinates should be known.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.