0

Uploaded my entire webpage on which my test is failing here: https://drive.google.com/file/d/1WHcwpQFi5Cxh1q1MupQEuSPk6CPZs2GC/view?usp=sharing

Below is my Selenium Java code auto-generated by Selenium Recorder IDE Plugin where I'm trying to enter text to input-type on my webpage.

driver.findElement(By.id("crtestrequest-cr_app_name")).click();
driver.findElement(By.id("crtestrequest-cr_app_name")).clear();
driver.findElement(By.id("crtestrequest-cr_app_name")).sendKeys("Allocation");

The above did not work and errors. Hence, I made the below changes to my code:

The below code works intermittently but rarely does it work.

js.executeScript("arguments[0].click();", driver.findElement(By.id("crtestrequest-cr_app_name")));
System.out.println("Title of the page is 7.19 -> " + driver.getTitle());
driver.findElement(By.id("crtestrequest-cr_app_name")).clear();
System.out.println("Title of the page is 7.20 -> " + driver.getTitle());
driver.findElement(By.id("crtestrequest-cr_app_name")).sendKeys("Allocation");
System.out.println("Title of the page is 7.21 -> " + driver.getTitle());

I get the below error running my test:

Title of the page is 7.18 -> Raise CR Request
Title of the page is 7.19 -> Raise CR Request
Title of the page is 7.20 -> Raise CR Request
Exception in thread "main" org.openqa.selenium.ElementNotInteractableException: element not interactable
  (Session info: chrome=75.0.3770.100)
Build info: version: '3.141.0', revision: '2ecb7d9a', time: '2018-10-31T20:09:30'
System info: host: 'myhost', ip: '10.9.140.15', os.name: 'Windows Server 2016', os.arch: 'x86', os.version: '10.0', java.version: '1.8.0_181'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 75.0.3770.100, chrome: {chromedriverVersion: 75.0.3770.140 (2d9f97485c7b..., userDataDir: C:\Usersxmwiis\AppData\Lo...}, goog:chromeOptions: {debuggerAddress: localhost:62388}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: XP, platformName: XP, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}
Session ID: 5d2f84a25fb9daaaf3c5360a3f6c17e9
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
        at java.lang.reflect.Constructor.newInstance(Unknown Source)
        at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
        at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
        at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
        at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
        at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
        at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
        at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:285)
        at org.openqa.selenium.remote.RemoteWebElement.sendKeys(RemoteWebElement.java:106)
        at pack.SynvmRequest.testSynvmRequest(SynvmRequest.java:301)
        at pack.SynvmRequest.main(SynvmRequest.java:538)

Here is the relevant view source code for the text input from the web page:

<div class="row"><div class="col-lg-12"></div></div>
<div class="row"><div class="col-lg-12"></div></div>

<div class="row"><div class="col-lg-12"><div class="form-group col-lg-6 field-crtestrequest-cr_app_name required">

<label class="control-label" for="crtestrequest-cr_app_name">App Name as per AOP</label>

<input type="text" id="crtestrequest-cr_app_name" class="form-control" name="CRTestRequest[cr_app_name]" value="" maxlength="150" aria-required="true"> 

Issue trying @Norayr Sargsyan solution:

Title of the page is 7.19 -> Raise CR Request
Exception in thread "main" org.openqa.selenium.ElementClickInterceptedException: element click intercepted: Element <label class="control-label" for="crtestrequest-cr_app_name">...</label> is not clickable at point (206, 500). Other element would receive the click: <div class="panel-body" style="margin-top:-21px;">...</div>
  (Session info: chrome=75.0.3770.100)
Build info: version: '3.141.0', revision: '2ecb7d9a', time: '2018-10-31T20:09:30'
System info: host: 'myhost', ip: '10.9.140.15', os.name: 'Windows Server 2016', os.arch: 'x86', os.version: '10.0', java.version: '1.8.0_181'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 75.0.3770.100, chrome: {chromedriverVersion: 75.0.3770.140 (2d9f97485c7b..., userDataDir: C:\Usersxmwiis\AppData\Lo...}, goog:chromeOptions: {debuggerAddress: localhost:63030}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: XP, platformName: XP, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}
Session ID: 4791be3194b3fa8635c5b82962202579
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
        at java.lang.reflect.Constructor.newInstance(Unknown Source)
        at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
        at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
        at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
        at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
        at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
        at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
        at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:285)
        at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:84)
        at pack.SynvmRequest.testSynvmRequest(SynvmRequest.java:301)
        at pack.SynvmRequest.main(SynvmRequest.java:542)

Issue trying @Norayr Sargsyan second solution with for loop & Actions class

Title of the page is 7.19 -> Raise CR Request
Trying to recover from a stale element :stale element reference: element is not attached to the page document
  (Session info: chrome=75.0.3770.100)
For documentation on this error, please visit: http://seleniumhq.org/exceptions/stale_element_reference.html
Build info: version: '3.141.0', revision: '2ecb7d9a', time: '2018-10-31T20:09:30'
System info: host: 'myhost', ip: '10.9.140.15', os.name: 'Windows Server 2016', os.arch: 'x86', os.version: '10.0', java.version: '1.8.0_181'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 75.0.3770.100, chrome: {chromedriverVersion: 75.0.3770.140 (2d9f97485c7b..., userDataDir: C:\Usersxmwiis\AppData\Lo...}, goog:chromeOptions: {debuggerAddress: localhost:64331}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: XP, platformName: XP, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}
Session ID: 1c190d50b7d77839ad4d4d4452576ad3
Title of the page is 7.19 -> Raise CR Request
Exception in thread "main" org.openqa.selenium.ElementClickInterceptedException: element click intercepted: Element <input type="text" id="crtestrequest-cr_app_name" class="form-control" name="CRTestRequest[cr_app_name]" value="" maxlength="150" aria-required="true"> is not clickable at point (533, 496). Other element would receive the click: <footer class="main-footer main-content clearfix">...</footer>
  (Session info: chrome=75.0.3770.100)
Build info: version: '3.141.0', revision: '2ecb7d9a', time: '2018-10-31T20:09:30'
System info: host: 'myhost', ip: '10.9.140.15', os.name: 'Windows Server 2016', os.arch: 'x86', os.version: '10.0', java.version: '1.8.0_181'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 75.0.3770.100, chrome: {chromedriverVersion: 75.0.3770.140 (2d9f97485c7b..., userDataDir: C:\Usersxmwiis\AppData\Lo...}, goog:chromeOptions: {debuggerAddress: localhost:64331}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: XP, platformName: XP, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}
Session ID: 1c190d50b7d77839ad4d4d4452576ad3
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
        at java.lang.reflect.Constructor.newInstance(Unknown Source)
        at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
        at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
        at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
        at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
        at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
        at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
        at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:285)
        at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:84)
        at pack.SynvmRequest.testSynvmRequest(SynvmRequest.java:311)
        at pack.SynvmRequest.main(SynvmRequest.java:576)

Issue trying @DebanjanB solution:

Title of the page is 7.19 -> Raise CR Request
Exception in thread "main" org.openqa.selenium.StaleElementReferenceException: stale element reference: element is not attached to the page document
  (Session info: chrome=75.0.3770.100)
For documentation on this error, please visit: http://seleniumhq.org/exceptions/stale_element_reference.html
Build info: version: '3.141.0', revision: '2ecb7d9a', time: '2018-10-31T20:09:30'
System info: host: 'myhost', ip: '10.9.140.15', os.name: 'Windows Server 2016', os.arch: 'x86', os.version: '10.0', java.version: '1.8.0_181'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 75.0.3770.100, chrome: {chromedriverVersion: 75.0.3770.140 (2d9f97485c7b..., userDataDir: C:\Usersxmwiis\AppData\Lo...}, goog:chromeOptions: {debuggerAddress: localhost:63253}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: XP, platformName: XP, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}
Session ID: 4699d09a1abe8089612d70509d5047e4
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
        at java.lang.reflect.Constructor.newInstance(Unknown Source)
        at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
        at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
        at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
        at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
        at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
        at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
        at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:285)
        at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:84)
        at pack.SynvmRequest.testSynvmRequest(SynvmRequest.java:307)
        at pack.SynvmRequest.main(SynvmRequest.java:551)

Can you please suggest how can I get it to work?

Ashar
  • 2,942
  • 10
  • 58
  • 122
  • You've tried [Class Actions](https://www.selenium.dev/selenium/docs/api/java/org/openqa/selenium/interactions/Actions.html)? – frianH Jul 07 '20 at 13:04
  • Yes, but it does not work... Updated the error from `Actions` class in the original post. – Ashar Jul 07 '20 at 13:14

3 Answers3

1

I have been trying past 24 hours to get this to work and finally did.

Before, I trigger the Search Assests button as visible in my video @ 1.11 minutes I tried the below code which worked.

WebElement ele = driver.findElement(By.id("crtestrequest-cr_app_code"));
JavascriptExecutor exec = (JavascriptExecutor)driver;
exec.executeScript("arguments[0].click();", ele);
driver.findElement(By.id("crtestrequest-cr_app_code")).clear();
driver.findElement(By.id("crtestrequest-cr_app_code")).sendKeys("Allocation");
Ashar
  • 2,942
  • 10
  • 58
  • 122
0

I think the element which you needed is present on the DOM, but it is not in a state that you can interact with them.

WebDriverWait wait = new WebDriverWait(driver, 10);
wait.ignoring(StaleElementReferenceException.class).until(ExpectedConditions.elementToBeClickable(By.id("crtestrequest-cr_app_name")));
WebLement input = driver.findElement(By.id("crtestrequest-cr_app_name"))
input.click();
input.clear();
input.sendKeys("123");

or

for(int i=0; i<=2;i++){
  try{
     WebLement input = driver.findElement(By.id("crtestrequest-cr_app_name"))
     Actions actions = new Actions(driver);
     actions.moveToElement(input).perform();
     input.click();
     break;
   } catch (StaleElementReferenceException e) {
           System.out.println("Trying to recover from a stale element :" + e.getMessage());
   }
}
Norayr Sargsyan
  • 1,737
  • 1
  • 12
  • 26
  • I tried your suggestion but it still does not work. Updated the Original post with your suggestion's output @Norayr Sargsyan – Ashar Jul 07 '20 at 12:03
  • @Ashar If you can provide the URL of you test and the element which you want to interact, I will send you the solution – Norayr Sargsyan Jul 07 '20 at 12:05
  • please find the error updated in my original post trying your suggestion. I can try uploading the whole webpage but this is an internal webpage. Also, copying- pasting the entire view source of the webpage distorts the look and feel but i can try sharing that. – Ashar Jul 07 '20 at 12:09
  • @Ashar I have updated my answer, check and let me know – Norayr Sargsyan Jul 07 '20 at 12:16
  • with this change that you suggested i.e `wait.ignoring` i get the same error as stated in the OP for your suggestion. Regarding `Actions` solution how where did you get `element` in `element.click()`? Could you write the complete solution for `Actions` ? – Ashar Jul 07 '20 at 12:30
  • Sadly `element is not attached to the page document` error for your other suggestion with `Actions` @Norayr Sargsyan – Ashar Jul 07 '20 at 12:54
  • Updated my original post with second part error output `Trying to recover from a stale element` – Ashar Jul 07 '20 at 13:27
  • You should provide the URL of your website, there is a case that you did not mention in question, and I will check it myself – Norayr Sargsyan Jul 07 '20 at 13:37
  • Sure, i will save and share the webpage as PHP as it is not accessible over the internet. Meanwhile, I have recorded a video demonstrating the problem `https://www.youtube.com/watch?v=-Lk6_SgRkpk` . If you can have a look. – Ashar Jul 07 '20 at 13:47
  • @ Norayr Sargsyan I shared the entire webpage here: https://drive.google.com/file/d/1WHcwpQFi5Cxh1q1MupQEuSPk6CPZs2GC/view?usp=sharing and youtube link here: https://www.youtube.com/watch?v=-Lk6_SgRkpk – Ashar Jul 07 '20 at 14:43
  • @Ashar with your source code it possible to senskey() in input WebElement input = driver.findElement(By.id("crtestrequest-cr_app_name")); input.sendKeys("anything"); – Norayr Sargsyan Jul 07 '20 at 14:51
  • it does not work either. I guess due to the popup action right before the input issue at 1:11 minutes of the video here https://youtu.be/-Lk6_SgRkpk?t=71 ... could that lead to loss of focus / control on the window or resets the DOM ? if so, what should be the solution in that case ? – Ashar Jul 07 '20 at 15:37
0

Instead of invoking sendKeys() to the <label> you need to invoke on the <input> element and ideally to click() on the element you need to use WebDriverWait for the elementToBeClickable() and you can use either of the following Locator Strategies:

  • cssSelector:

    WebElement element = new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("div.row div.field-crtestrequest-cr_app_name>label[for='crtestrequest-cr_app_name']")));
    element.click();
    element.clear();
    element.sendKeys("Allocation");
    
  • xpath:

    WebElement element = new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@class='row']//div[contains(@class, 'field-crtestrequest-cr_app_name')]/label[@for='crtestrequest-cr_app_name']")));
    element.click();
    element.clear();
    element.sendKeys("Allocation");
    

References

You can find a couple of relevant discussions on ElementNotInteractableException in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • I tried your suggestion but it still does not work. Updated the Original post with your suggestion's output @DebanjanB – Ashar Jul 07 '20 at 12:03
  • @Ashar Checkout the updated answer and let me know the status. – undetected Selenium Jul 07 '20 at 12:54
  • I get a couple of issues compiling your updated suggestion @DebanjanB. 1. element Object is defined twice ... 2. `error: incompatible types: inference variable V has incompatible bounds` . Can you please correct the code as I'm not sure? – Ashar Jul 07 '20 at 13:05
  • @Ashar Checkout the updated answer and let me know the status. – undetected Selenium Jul 07 '20 at 13:18
  • Does not work @DebanjanB I guess due to the popup action right before the input could be the cause of the issue. Look at 1:11 minutes of the video here youtu.be/-Lk6_SgRkpk?t=71 for the popup actions before I go back to the main window. Is there an option to get focus control back to the main Window ? – Ashar Jul 07 '20 at 16:07