org.openqa.selenium.ElementNotInteractableException: Element is not reachable by keyboard: while sending text to FirstName field in Facebook
The error is :
Exception in thread "main" org.openqa.selenium.ElementNotInteractableException: Element <div id="u_0_b" class="_5dbb"> is not reachable by keyboard
The code is:
System.setProperty("webdriver.gecko.driver","//Users//rozali//Documents//Selenium//geckodriver");
WebDriver driver = new FirefoxDriver();
driver.get("http://www.facebook.com");
driver.manage().window().maximize();
//entering first name
driver.findElement(By.id("u_0_b")).click();
driver.findElement(By.id("u_0_b")).sendKeys("testing it ");
//DOB
Select sel1 = new Select(driver.findElement(By.xpath(".//*[@id='month']")));
sel1.selectByIndex(4);
Select sel2 = new Select(driver.findElement(By.xpath(".//*[@id='day']")));
sel2.selectByValue("6");
Select sel3 = new Select(driver.findElement(By.xpath(".//*[@id='year']")));
sel3.selectByValue("2013");
//clicking sign up
driver.findElement(By.id("u_0_t")).click();
facebook selenium react-native selenium-webdriver webdriver
add a comment |
The error is :
Exception in thread "main" org.openqa.selenium.ElementNotInteractableException: Element <div id="u_0_b" class="_5dbb"> is not reachable by keyboard
The code is:
System.setProperty("webdriver.gecko.driver","//Users//rozali//Documents//Selenium//geckodriver");
WebDriver driver = new FirefoxDriver();
driver.get("http://www.facebook.com");
driver.manage().window().maximize();
//entering first name
driver.findElement(By.id("u_0_b")).click();
driver.findElement(By.id("u_0_b")).sendKeys("testing it ");
//DOB
Select sel1 = new Select(driver.findElement(By.xpath(".//*[@id='month']")));
sel1.selectByIndex(4);
Select sel2 = new Select(driver.findElement(By.xpath(".//*[@id='day']")));
sel2.selectByValue("6");
Select sel3 = new Select(driver.findElement(By.xpath(".//*[@id='year']")));
sel3.selectByValue("2013");
//clicking sign up
driver.findElement(By.id("u_0_t")).click();
facebook selenium react-native selenium-webdriver webdriver
as your error states,driver.findElement(By.id("u_0_b")).sendKeys("testing it ")
looks like it's not interactable. Go through your script step by step and see if it's showing, and accessible. Is there an element overlaying it?
– sircapsalot
Apr 16 '18 at 19:58
At first step it is showing the same error. I have check each line one by one but same error is visible every time.
– Rozmeen
Apr 16 '18 at 21:10
add a comment |
The error is :
Exception in thread "main" org.openqa.selenium.ElementNotInteractableException: Element <div id="u_0_b" class="_5dbb"> is not reachable by keyboard
The code is:
System.setProperty("webdriver.gecko.driver","//Users//rozali//Documents//Selenium//geckodriver");
WebDriver driver = new FirefoxDriver();
driver.get("http://www.facebook.com");
driver.manage().window().maximize();
//entering first name
driver.findElement(By.id("u_0_b")).click();
driver.findElement(By.id("u_0_b")).sendKeys("testing it ");
//DOB
Select sel1 = new Select(driver.findElement(By.xpath(".//*[@id='month']")));
sel1.selectByIndex(4);
Select sel2 = new Select(driver.findElement(By.xpath(".//*[@id='day']")));
sel2.selectByValue("6");
Select sel3 = new Select(driver.findElement(By.xpath(".//*[@id='year']")));
sel3.selectByValue("2013");
//clicking sign up
driver.findElement(By.id("u_0_t")).click();
facebook selenium react-native selenium-webdriver webdriver
The error is :
Exception in thread "main" org.openqa.selenium.ElementNotInteractableException: Element <div id="u_0_b" class="_5dbb"> is not reachable by keyboard
The code is:
System.setProperty("webdriver.gecko.driver","//Users//rozali//Documents//Selenium//geckodriver");
WebDriver driver = new FirefoxDriver();
driver.get("http://www.facebook.com");
driver.manage().window().maximize();
//entering first name
driver.findElement(By.id("u_0_b")).click();
driver.findElement(By.id("u_0_b")).sendKeys("testing it ");
//DOB
Select sel1 = new Select(driver.findElement(By.xpath(".//*[@id='month']")));
sel1.selectByIndex(4);
Select sel2 = new Select(driver.findElement(By.xpath(".//*[@id='day']")));
sel2.selectByValue("6");
Select sel3 = new Select(driver.findElement(By.xpath(".//*[@id='year']")));
sel3.selectByValue("2013");
//clicking sign up
driver.findElement(By.id("u_0_t")).click();
facebook selenium react-native selenium-webdriver webdriver
facebook selenium react-native selenium-webdriver webdriver
edited Apr 17 '18 at 14:10
DebanjanB
42.5k94183
42.5k94183
asked Apr 16 '18 at 19:35
RozmeenRozmeen
2816
2816
as your error states,driver.findElement(By.id("u_0_b")).sendKeys("testing it ")
looks like it's not interactable. Go through your script step by step and see if it's showing, and accessible. Is there an element overlaying it?
– sircapsalot
Apr 16 '18 at 19:58
At first step it is showing the same error. I have check each line one by one but same error is visible every time.
– Rozmeen
Apr 16 '18 at 21:10
add a comment |
as your error states,driver.findElement(By.id("u_0_b")).sendKeys("testing it ")
looks like it's not interactable. Go through your script step by step and see if it's showing, and accessible. Is there an element overlaying it?
– sircapsalot
Apr 16 '18 at 19:58
At first step it is showing the same error. I have check each line one by one but same error is visible every time.
– Rozmeen
Apr 16 '18 at 21:10
as your error states,
driver.findElement(By.id("u_0_b")).sendKeys("testing it ")
looks like it's not interactable. Go through your script step by step and see if it's showing, and accessible. Is there an element overlaying it?– sircapsalot
Apr 16 '18 at 19:58
as your error states,
driver.findElement(By.id("u_0_b")).sendKeys("testing it ")
looks like it's not interactable. Go through your script step by step and see if it's showing, and accessible. Is there an element overlaying it?– sircapsalot
Apr 16 '18 at 19:58
At first step it is showing the same error. I have check each line one by one but same error is visible every time.
– Rozmeen
Apr 16 '18 at 21:10
At first step it is showing the same error. I have check each line one by one but same error is visible every time.
– Rozmeen
Apr 16 '18 at 21:10
add a comment |
2 Answers
2
active
oldest
votes
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 be 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()
orsendKeys()
on any<p>
or<div>
tag, instead invokeclick()
on the desired<input>
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.cssSelector("button.nsg-button"))).click();Incase of permanent overlay use
executeScript()
method from JavascriptExecutor interface as follows:import org.openqa.selenium.JavascriptExecutor;
String inputText = "Rozmeen";
WebElement myElement = driver.findElement(By.id("u_0_b"));
String js = "arguments[0].setAttribute('value','"+inputText+"')"
((JavascriptExecutor) driver).executeScript(js, myElement);You will find a detailed discussion in Using JS to enter text, but if I input text in one text box, the value already entered is getting deleted
Incase presence of attributes e.g.
class="ng-hide"
,style="display: none"
, etc useexecuteScript()
method from JavascriptExecutor interface to edit and reset thestyle="display: none"
attribute tostyle="display: block"
as follows:import org.openqa.selenium.JavascriptExecutor;
((JavascriptExecutor) driver).executeScript("document.getElementById('ID').style.display='block';");You will find a detailed discussion in Can't fill in the Hidden text area element
References
- For input[type=file], should allow sendKeys even when display=none
- Special-casing file upload controls in keyboard-interactability check
- Element is not reachable by keyboard
- Input field with display: none is not interactable at all?
This particular issue
If you look into the HTML of Facebook login page, the application contains React Native elements. So an element once represented with id
as u_0_b in your system may not be represented by the same id
as u_0_b in the next run on your system. Hence, we have to take help of Dynamic Locator Strategy. You can use the following code block to perform your intended steps :
Code Block :
System.setProperty("webdriver.gecko.driver", "C:\Utility\BrowserDrivers\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.get("https://www.facebook.com");
driver.findElement(By.xpath("//input[@name='firstname' and contains(@class,'inputtext')]")).sendKeys("testing it ");
//DOB
Select sel1 = new Select(driver.findElement(By.xpath(".//*[@id='month']")));
sel1.selectByIndex(4);
Select sel2 = new Select(driver.findElement(By.xpath(".//*[@id='day']")));
sel2.selectByValue("6");
Select sel3 = new Select(driver.findElement(By.xpath(".//*[@id='year']")));
sel3.selectByValue("2013");
//clicking sign up
driver.findElement(By.xpath("//button[@name='websubmit' and contains(.,'Sign Up')]")).click();Browser Client :
Update
Addressing the error:
org.openqa.selenium.ElementNotInteractableException: Element is not reachable by keyboard
Have become more easier with the availability of Firefox capability moz:webdriverClick
moz:webdriverClick()
Through webdriverClick()
you can pass a boolean value to indicate which kind of interactability checks to run when performing a click or sending keys to an elements. For Firefoxen prior to v58.0 some legacy code as imported from an older version of FirefoxDriver was in use. With the availability of Firefox v58 the interactability checks as required by the WebDriver specification are enabled by default. This means geckodriver will additionally check if an element is obscured by another when clicking, and if an element is focusable for sending keys. Because of this change in behaviour, we are aware that some extra errors could be returned. In most cases the test in question might have to be updated so it's conform with the new checks.
To temporarily disable the WebDriver conformant checks use false
as value for this capability.
Note: This capability exists only temporarily, and that it will be removed once the interactability checks have been stabilized.
add a comment |
You can try this code :
public class Rozmeen
static WebDriver driver;
static WebDriverWait wait;
public static void main(String args) throws InterruptedException
System.setProperty("webdriver.gecko.driver", "F:\Automation\geckodriver.exe");
driver = new FirefoxDriver();
driver.manage().window().maximize();
WebDriverWait wait = new WebDriverWait(driver, 40);
driver.get("http://www.facebook.com");
//entering first name
wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.id("pagelet_bluebar"))));
driver.findElement(By.name("firstname")).sendKeys("testing it ");
//DOB
selectFromDropDown(driver.findElement(By.name("birthday_day")), "4");
selectFromDropDown(driver.findElement(By.name("birthday_month")), "Jun");
selectFromDropDown(driver.findElement(By.name("birthday_year")), "2013");
//clicking sign up
wait.until(ExpectedConditions.elementToBeClickable(driver.findElement(By.name("websubmit"))));
driver.findElement(By.name("websubmit")).click();
public static void selectFromDropDown(WebElement element , String Visibletext)
Select select = new Select(element);
select.selectByVisibleText(Visibletext);
try out this code and let me know the status.
i tried using the wait commands but still it was not working.
– Rozmeen
Apr 17 '18 at 13:52
What is the error you are getting ?
– cruisepandey
Apr 18 '18 at 6:26
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f49864965%2forg-openqa-selenium-elementnotinteractableexception-element-is-not-reachable-by%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
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 be 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()
orsendKeys()
on any<p>
or<div>
tag, instead invokeclick()
on the desired<input>
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.cssSelector("button.nsg-button"))).click();Incase of permanent overlay use
executeScript()
method from JavascriptExecutor interface as follows:import org.openqa.selenium.JavascriptExecutor;
String inputText = "Rozmeen";
WebElement myElement = driver.findElement(By.id("u_0_b"));
String js = "arguments[0].setAttribute('value','"+inputText+"')"
((JavascriptExecutor) driver).executeScript(js, myElement);You will find a detailed discussion in Using JS to enter text, but if I input text in one text box, the value already entered is getting deleted
Incase presence of attributes e.g.
class="ng-hide"
,style="display: none"
, etc useexecuteScript()
method from JavascriptExecutor interface to edit and reset thestyle="display: none"
attribute tostyle="display: block"
as follows:import org.openqa.selenium.JavascriptExecutor;
((JavascriptExecutor) driver).executeScript("document.getElementById('ID').style.display='block';");You will find a detailed discussion in Can't fill in the Hidden text area element
References
- For input[type=file], should allow sendKeys even when display=none
- Special-casing file upload controls in keyboard-interactability check
- Element is not reachable by keyboard
- Input field with display: none is not interactable at all?
This particular issue
If you look into the HTML of Facebook login page, the application contains React Native elements. So an element once represented with id
as u_0_b in your system may not be represented by the same id
as u_0_b in the next run on your system. Hence, we have to take help of Dynamic Locator Strategy. You can use the following code block to perform your intended steps :
Code Block :
System.setProperty("webdriver.gecko.driver", "C:\Utility\BrowserDrivers\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.get("https://www.facebook.com");
driver.findElement(By.xpath("//input[@name='firstname' and contains(@class,'inputtext')]")).sendKeys("testing it ");
//DOB
Select sel1 = new Select(driver.findElement(By.xpath(".//*[@id='month']")));
sel1.selectByIndex(4);
Select sel2 = new Select(driver.findElement(By.xpath(".//*[@id='day']")));
sel2.selectByValue("6");
Select sel3 = new Select(driver.findElement(By.xpath(".//*[@id='year']")));
sel3.selectByValue("2013");
//clicking sign up
driver.findElement(By.xpath("//button[@name='websubmit' and contains(.,'Sign Up')]")).click();Browser Client :
Update
Addressing the error:
org.openqa.selenium.ElementNotInteractableException: Element is not reachable by keyboard
Have become more easier with the availability of Firefox capability moz:webdriverClick
moz:webdriverClick()
Through webdriverClick()
you can pass a boolean value to indicate which kind of interactability checks to run when performing a click or sending keys to an elements. For Firefoxen prior to v58.0 some legacy code as imported from an older version of FirefoxDriver was in use. With the availability of Firefox v58 the interactability checks as required by the WebDriver specification are enabled by default. This means geckodriver will additionally check if an element is obscured by another when clicking, and if an element is focusable for sending keys. Because of this change in behaviour, we are aware that some extra errors could be returned. In most cases the test in question might have to be updated so it's conform with the new checks.
To temporarily disable the WebDriver conformant checks use false
as value for this capability.
Note: This capability exists only temporarily, and that it will be removed once the interactability checks have been stabilized.
add a comment |
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 be 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()
orsendKeys()
on any<p>
or<div>
tag, instead invokeclick()
on the desired<input>
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.cssSelector("button.nsg-button"))).click();Incase of permanent overlay use
executeScript()
method from JavascriptExecutor interface as follows:import org.openqa.selenium.JavascriptExecutor;
String inputText = "Rozmeen";
WebElement myElement = driver.findElement(By.id("u_0_b"));
String js = "arguments[0].setAttribute('value','"+inputText+"')"
((JavascriptExecutor) driver).executeScript(js, myElement);You will find a detailed discussion in Using JS to enter text, but if I input text in one text box, the value already entered is getting deleted
Incase presence of attributes e.g.
class="ng-hide"
,style="display: none"
, etc useexecuteScript()
method from JavascriptExecutor interface to edit and reset thestyle="display: none"
attribute tostyle="display: block"
as follows:import org.openqa.selenium.JavascriptExecutor;
((JavascriptExecutor) driver).executeScript("document.getElementById('ID').style.display='block';");You will find a detailed discussion in Can't fill in the Hidden text area element
References
- For input[type=file], should allow sendKeys even when display=none
- Special-casing file upload controls in keyboard-interactability check
- Element is not reachable by keyboard
- Input field with display: none is not interactable at all?
This particular issue
If you look into the HTML of Facebook login page, the application contains React Native elements. So an element once represented with id
as u_0_b in your system may not be represented by the same id
as u_0_b in the next run on your system. Hence, we have to take help of Dynamic Locator Strategy. You can use the following code block to perform your intended steps :
Code Block :
System.setProperty("webdriver.gecko.driver", "C:\Utility\BrowserDrivers\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.get("https://www.facebook.com");
driver.findElement(By.xpath("//input[@name='firstname' and contains(@class,'inputtext')]")).sendKeys("testing it ");
//DOB
Select sel1 = new Select(driver.findElement(By.xpath(".//*[@id='month']")));
sel1.selectByIndex(4);
Select sel2 = new Select(driver.findElement(By.xpath(".//*[@id='day']")));
sel2.selectByValue("6");
Select sel3 = new Select(driver.findElement(By.xpath(".//*[@id='year']")));
sel3.selectByValue("2013");
//clicking sign up
driver.findElement(By.xpath("//button[@name='websubmit' and contains(.,'Sign Up')]")).click();Browser Client :
Update
Addressing the error:
org.openqa.selenium.ElementNotInteractableException: Element is not reachable by keyboard
Have become more easier with the availability of Firefox capability moz:webdriverClick
moz:webdriverClick()
Through webdriverClick()
you can pass a boolean value to indicate which kind of interactability checks to run when performing a click or sending keys to an elements. For Firefoxen prior to v58.0 some legacy code as imported from an older version of FirefoxDriver was in use. With the availability of Firefox v58 the interactability checks as required by the WebDriver specification are enabled by default. This means geckodriver will additionally check if an element is obscured by another when clicking, and if an element is focusable for sending keys. Because of this change in behaviour, we are aware that some extra errors could be returned. In most cases the test in question might have to be updated so it's conform with the new checks.
To temporarily disable the WebDriver conformant checks use false
as value for this capability.
Note: This capability exists only temporarily, and that it will be removed once the interactability checks have been stabilized.
add a comment |
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 be 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()
orsendKeys()
on any<p>
or<div>
tag, instead invokeclick()
on the desired<input>
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.cssSelector("button.nsg-button"))).click();Incase of permanent overlay use
executeScript()
method from JavascriptExecutor interface as follows:import org.openqa.selenium.JavascriptExecutor;
String inputText = "Rozmeen";
WebElement myElement = driver.findElement(By.id("u_0_b"));
String js = "arguments[0].setAttribute('value','"+inputText+"')"
((JavascriptExecutor) driver).executeScript(js, myElement);You will find a detailed discussion in Using JS to enter text, but if I input text in one text box, the value already entered is getting deleted
Incase presence of attributes e.g.
class="ng-hide"
,style="display: none"
, etc useexecuteScript()
method from JavascriptExecutor interface to edit and reset thestyle="display: none"
attribute tostyle="display: block"
as follows:import org.openqa.selenium.JavascriptExecutor;
((JavascriptExecutor) driver).executeScript("document.getElementById('ID').style.display='block';");You will find a detailed discussion in Can't fill in the Hidden text area element
References
- For input[type=file], should allow sendKeys even when display=none
- Special-casing file upload controls in keyboard-interactability check
- Element is not reachable by keyboard
- Input field with display: none is not interactable at all?
This particular issue
If you look into the HTML of Facebook login page, the application contains React Native elements. So an element once represented with id
as u_0_b in your system may not be represented by the same id
as u_0_b in the next run on your system. Hence, we have to take help of Dynamic Locator Strategy. You can use the following code block to perform your intended steps :
Code Block :
System.setProperty("webdriver.gecko.driver", "C:\Utility\BrowserDrivers\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.get("https://www.facebook.com");
driver.findElement(By.xpath("//input[@name='firstname' and contains(@class,'inputtext')]")).sendKeys("testing it ");
//DOB
Select sel1 = new Select(driver.findElement(By.xpath(".//*[@id='month']")));
sel1.selectByIndex(4);
Select sel2 = new Select(driver.findElement(By.xpath(".//*[@id='day']")));
sel2.selectByValue("6");
Select sel3 = new Select(driver.findElement(By.xpath(".//*[@id='year']")));
sel3.selectByValue("2013");
//clicking sign up
driver.findElement(By.xpath("//button[@name='websubmit' and contains(.,'Sign Up')]")).click();Browser Client :
Update
Addressing the error:
org.openqa.selenium.ElementNotInteractableException: Element is not reachable by keyboard
Have become more easier with the availability of Firefox capability moz:webdriverClick
moz:webdriverClick()
Through webdriverClick()
you can pass a boolean value to indicate which kind of interactability checks to run when performing a click or sending keys to an elements. For Firefoxen prior to v58.0 some legacy code as imported from an older version of FirefoxDriver was in use. With the availability of Firefox v58 the interactability checks as required by the WebDriver specification are enabled by default. This means geckodriver will additionally check if an element is obscured by another when clicking, and if an element is focusable for sending keys. Because of this change in behaviour, we are aware that some extra errors could be returned. In most cases the test in question might have to be updated so it's conform with the new checks.
To temporarily disable the WebDriver conformant checks use false
as value for this capability.
Note: This capability exists only temporarily, and that it will be removed once the interactability checks have been stabilized.
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 be 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()
orsendKeys()
on any<p>
or<div>
tag, instead invokeclick()
on the desired<input>
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.cssSelector("button.nsg-button"))).click();Incase of permanent overlay use
executeScript()
method from JavascriptExecutor interface as follows:import org.openqa.selenium.JavascriptExecutor;
String inputText = "Rozmeen";
WebElement myElement = driver.findElement(By.id("u_0_b"));
String js = "arguments[0].setAttribute('value','"+inputText+"')"
((JavascriptExecutor) driver).executeScript(js, myElement);You will find a detailed discussion in Using JS to enter text, but if I input text in one text box, the value already entered is getting deleted
Incase presence of attributes e.g.
class="ng-hide"
,style="display: none"
, etc useexecuteScript()
method from JavascriptExecutor interface to edit and reset thestyle="display: none"
attribute tostyle="display: block"
as follows:import org.openqa.selenium.JavascriptExecutor;
((JavascriptExecutor) driver).executeScript("document.getElementById('ID').style.display='block';");You will find a detailed discussion in Can't fill in the Hidden text area element
References
- For input[type=file], should allow sendKeys even when display=none
- Special-casing file upload controls in keyboard-interactability check
- Element is not reachable by keyboard
- Input field with display: none is not interactable at all?
This particular issue
If you look into the HTML of Facebook login page, the application contains React Native elements. So an element once represented with id
as u_0_b in your system may not be represented by the same id
as u_0_b in the next run on your system. Hence, we have to take help of Dynamic Locator Strategy. You can use the following code block to perform your intended steps :
Code Block :
System.setProperty("webdriver.gecko.driver", "C:\Utility\BrowserDrivers\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.get("https://www.facebook.com");
driver.findElement(By.xpath("//input[@name='firstname' and contains(@class,'inputtext')]")).sendKeys("testing it ");
//DOB
Select sel1 = new Select(driver.findElement(By.xpath(".//*[@id='month']")));
sel1.selectByIndex(4);
Select sel2 = new Select(driver.findElement(By.xpath(".//*[@id='day']")));
sel2.selectByValue("6");
Select sel3 = new Select(driver.findElement(By.xpath(".//*[@id='year']")));
sel3.selectByValue("2013");
//clicking sign up
driver.findElement(By.xpath("//button[@name='websubmit' and contains(.,'Sign Up')]")).click();Browser Client :
Update
Addressing the error:
org.openqa.selenium.ElementNotInteractableException: Element is not reachable by keyboard
Have become more easier with the availability of Firefox capability moz:webdriverClick
moz:webdriverClick()
Through webdriverClick()
you can pass a boolean value to indicate which kind of interactability checks to run when performing a click or sending keys to an elements. For Firefoxen prior to v58.0 some legacy code as imported from an older version of FirefoxDriver was in use. With the availability of Firefox v58 the interactability checks as required by the WebDriver specification are enabled by default. This means geckodriver will additionally check if an element is obscured by another when clicking, and if an element is focusable for sending keys. Because of this change in behaviour, we are aware that some extra errors could be returned. In most cases the test in question might have to be updated so it's conform with the new checks.
To temporarily disable the WebDriver conformant checks use false
as value for this capability.
Note: This capability exists only temporarily, and that it will be removed once the interactability checks have been stabilized.
edited Jun 4 '18 at 10:57
answered Apr 17 '18 at 7:24
DebanjanBDebanjanB
42.5k94183
42.5k94183
add a comment |
add a comment |
You can try this code :
public class Rozmeen
static WebDriver driver;
static WebDriverWait wait;
public static void main(String args) throws InterruptedException
System.setProperty("webdriver.gecko.driver", "F:\Automation\geckodriver.exe");
driver = new FirefoxDriver();
driver.manage().window().maximize();
WebDriverWait wait = new WebDriverWait(driver, 40);
driver.get("http://www.facebook.com");
//entering first name
wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.id("pagelet_bluebar"))));
driver.findElement(By.name("firstname")).sendKeys("testing it ");
//DOB
selectFromDropDown(driver.findElement(By.name("birthday_day")), "4");
selectFromDropDown(driver.findElement(By.name("birthday_month")), "Jun");
selectFromDropDown(driver.findElement(By.name("birthday_year")), "2013");
//clicking sign up
wait.until(ExpectedConditions.elementToBeClickable(driver.findElement(By.name("websubmit"))));
driver.findElement(By.name("websubmit")).click();
public static void selectFromDropDown(WebElement element , String Visibletext)
Select select = new Select(element);
select.selectByVisibleText(Visibletext);
try out this code and let me know the status.
i tried using the wait commands but still it was not working.
– Rozmeen
Apr 17 '18 at 13:52
What is the error you are getting ?
– cruisepandey
Apr 18 '18 at 6:26
add a comment |
You can try this code :
public class Rozmeen
static WebDriver driver;
static WebDriverWait wait;
public static void main(String args) throws InterruptedException
System.setProperty("webdriver.gecko.driver", "F:\Automation\geckodriver.exe");
driver = new FirefoxDriver();
driver.manage().window().maximize();
WebDriverWait wait = new WebDriverWait(driver, 40);
driver.get("http://www.facebook.com");
//entering first name
wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.id("pagelet_bluebar"))));
driver.findElement(By.name("firstname")).sendKeys("testing it ");
//DOB
selectFromDropDown(driver.findElement(By.name("birthday_day")), "4");
selectFromDropDown(driver.findElement(By.name("birthday_month")), "Jun");
selectFromDropDown(driver.findElement(By.name("birthday_year")), "2013");
//clicking sign up
wait.until(ExpectedConditions.elementToBeClickable(driver.findElement(By.name("websubmit"))));
driver.findElement(By.name("websubmit")).click();
public static void selectFromDropDown(WebElement element , String Visibletext)
Select select = new Select(element);
select.selectByVisibleText(Visibletext);
try out this code and let me know the status.
i tried using the wait commands but still it was not working.
– Rozmeen
Apr 17 '18 at 13:52
What is the error you are getting ?
– cruisepandey
Apr 18 '18 at 6:26
add a comment |
You can try this code :
public class Rozmeen
static WebDriver driver;
static WebDriverWait wait;
public static void main(String args) throws InterruptedException
System.setProperty("webdriver.gecko.driver", "F:\Automation\geckodriver.exe");
driver = new FirefoxDriver();
driver.manage().window().maximize();
WebDriverWait wait = new WebDriverWait(driver, 40);
driver.get("http://www.facebook.com");
//entering first name
wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.id("pagelet_bluebar"))));
driver.findElement(By.name("firstname")).sendKeys("testing it ");
//DOB
selectFromDropDown(driver.findElement(By.name("birthday_day")), "4");
selectFromDropDown(driver.findElement(By.name("birthday_month")), "Jun");
selectFromDropDown(driver.findElement(By.name("birthday_year")), "2013");
//clicking sign up
wait.until(ExpectedConditions.elementToBeClickable(driver.findElement(By.name("websubmit"))));
driver.findElement(By.name("websubmit")).click();
public static void selectFromDropDown(WebElement element , String Visibletext)
Select select = new Select(element);
select.selectByVisibleText(Visibletext);
try out this code and let me know the status.
You can try this code :
public class Rozmeen
static WebDriver driver;
static WebDriverWait wait;
public static void main(String args) throws InterruptedException
System.setProperty("webdriver.gecko.driver", "F:\Automation\geckodriver.exe");
driver = new FirefoxDriver();
driver.manage().window().maximize();
WebDriverWait wait = new WebDriverWait(driver, 40);
driver.get("http://www.facebook.com");
//entering first name
wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.id("pagelet_bluebar"))));
driver.findElement(By.name("firstname")).sendKeys("testing it ");
//DOB
selectFromDropDown(driver.findElement(By.name("birthday_day")), "4");
selectFromDropDown(driver.findElement(By.name("birthday_month")), "Jun");
selectFromDropDown(driver.findElement(By.name("birthday_year")), "2013");
//clicking sign up
wait.until(ExpectedConditions.elementToBeClickable(driver.findElement(By.name("websubmit"))));
driver.findElement(By.name("websubmit")).click();
public static void selectFromDropDown(WebElement element , String Visibletext)
Select select = new Select(element);
select.selectByVisibleText(Visibletext);
try out this code and let me know the status.
answered Apr 17 '18 at 5:59
cruisepandeycruisepandey
4,2762518
4,2762518
i tried using the wait commands but still it was not working.
– Rozmeen
Apr 17 '18 at 13:52
What is the error you are getting ?
– cruisepandey
Apr 18 '18 at 6:26
add a comment |
i tried using the wait commands but still it was not working.
– Rozmeen
Apr 17 '18 at 13:52
What is the error you are getting ?
– cruisepandey
Apr 18 '18 at 6:26
i tried using the wait commands but still it was not working.
– Rozmeen
Apr 17 '18 at 13:52
i tried using the wait commands but still it was not working.
– Rozmeen
Apr 17 '18 at 13:52
What is the error you are getting ?
– cruisepandey
Apr 18 '18 at 6:26
What is the error you are getting ?
– cruisepandey
Apr 18 '18 at 6:26
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f49864965%2forg-openqa-selenium-elementnotinteractableexception-element-is-not-reachable-by%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
as your error states,
driver.findElement(By.id("u_0_b")).sendKeys("testing it ")
looks like it's not interactable. Go through your script step by step and see if it's showing, and accessible. Is there an element overlaying it?– sircapsalot
Apr 16 '18 at 19:58
At first step it is showing the same error. I have check each line one by one but same error is visible every time.
– Rozmeen
Apr 16 '18 at 21:10