0

This is my below code I am executing

driver.findElement(By.xpath("//label[starts-with(text(),'Create Part...')]")).click();
        driver.manage().timeouts().implicitlyWait(70, TimeUnit.SECONDS);
        driver.manage().timeouts().pageLoadTimeout(70, TimeUnit.SECONDS);
        String parentWindowHandler = driver.getWindowHandle(); // Store your parent window
        String subWindowHandler = null;

        Set<String> handles = driver.getWindowHandles(); // get all window handles
        Iterator<String> iterator = handles.iterator();
        while (iterator.hasNext()){
            subWindowHandler = iterator.next();
        }
        driver.switchTo().window(subWindowHandler); // switch to popup window
        WebElement element = driver.findElement(By.xpath("//select[@id='Type-Field']//following-sibling::div//div[@class='selectize-input items full has-options has-items']"));
        element.clear();
        element.sendKeys("Suba");

I am trying clear the default value in the field and giving some value through sendkeys. Field gives dropdown suggestions on entering the value.

It is throwing error at element.clear() line.

Stack trace:

Exception in thread "main" org.openqa.selenium.InvalidElementStateException: 
invalid element state: Element must be user-editable in order to clear it.
(Session info: chrome=66.0.3359.181)
(Driver info: chromedriver=2.38.552522 
(437e6fbedfa8762dec75e2c5b3ddb86763dc9dcb),platform=Windows NT 6.1.7601 SP1 
x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 34 milliseconds
Build info: version: 'unknown', revision: '5234b32', time: '2017-03-10 
09:00:17 -0800'
System info: host: 'TMIC-PCS2200', ip: '3.235.34.200', os.name: 'Windows 7', 
os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_144'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, 
mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome= 
{chromedriverVersion=2.38.552522 (437e6fbedfa8762dec75e2c5b3ddb86763dc9dcb), 
userDataDir=C:\Users\KT0047~1\AppData\Local\Temp\scoped_dir11272_22577}, 
takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, 
handlesAlerts=true, hasTouchScreen=false, version=66.0.3359.181, 
platform=XP, browserConnectionEnabled=false, nativeEvents=true, 
acceptSslCerts=false, acceptInsecureCerts=false, 
locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, 
takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true, 
setWindowRect=true, unexpectedAlertBehaviour=}]
Session ID: 742100fb9b41517012003fc5abe12b71
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)

Please help me resolving my issue. I am using Selenium 3.3.1 version.

HTML code

<div class="selectize-input items full has-options has-items" data-dropdown-direction="down">
<div data-value="Part" class="item">Part</div>
<input type="text" autocomplete="off" tabindex="1" style="width: 4px; position: relative; left: 0px; opacity: 0; z-index: -10000;">
::after
</div>

Here Part is the default value.

kiran kumar
  • 35
  • 3
  • 7
  • Try to set wait (with this -> wait.until(ExpectedConditions.elementToBeClickable(By.id));) about 10s before element.clear(); – Zhivko.Kostadinov May 21 '18 at 13:41
  • Tried it. Still the same exception at the same line. – kiran kumar May 21 '18 at 14:04
  • Update the question with the page HTML – GPT14 May 21 '18 at 14:05
  • HTML code included. – kiran kumar May 21 '18 at 14:19
  • Are y sure for provided XPath? It seems very flaky? The problem is, your element is not found. Try with another locator strategy. – Zhivko.Kostadinov May 21 '18 at 14:21
  • You are calling the `clear()` method on a WebElement that is pointing to a div tag. You can only call the `.clear()` on input tags. Try modifying the xpath such that it is pointing to the input tag below the div – GPT14 May 21 '18 at 14:29
  • Yeah tried it. But still the same error. – kiran kumar May 21 '18 at 14:36
  • WebElement element = driver.findElement(By.xpath("//div[@class='selectize-input items full has-options has-items']//div[text()='Part']")); element.click(); element.clear(); element.sendKeys("Suba"); – kiran kumar May 21 '18 at 14:36
  • You are still trying to clear a div element! Clear only works when you call it on an input. Also you need to update the question with the full HTML – GPT14 May 21 '18 at 14:44
  • This is the new xpath ://select[@id='Type-Field']//following-sibling::div//div//input. Still the same error. – kiran kumar May 21 '18 at 14:54
  • Now my xpath is reaching the input tag – kiran kumar May 21 '18 at 14:54
  • @DebanjanB This should not have been flagged as a duplicate of that question. They are not the same error message or cause. – JeffC May 21 '18 at 15:37
  • Are you sure the new xpath, `//select[@id='Type-Field']//following-sibling::div//div//input` actually reaches the correct input field? It is very generic at this point and may be pointing to a hidden input field, or a field that is disabled. Use Google Chrome console to test that it points to the right element. You also might try `//select[@id='Type-Field']//following-sibling::div[contains(@class,'selectize-input')]/div[contains(@class,'item')]/input` as something a little more directed. – MivaScott May 21 '18 at 16:12

0 Answers0