Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clear date input fails on chromewebdriver

I ran into a problem while switching from firefoxdriver to chromedriver with selenium, it was working fine in FF but now when I try to clear a date input field I have this error:

Caused by: org.openqa.selenium.InvalidElementStateException: Element must be user-editable
in order to clear it. (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 38 milliseconds
Build info: version: '2.31.0', revision: '1bd294d185a80fa4206dfeab80ba773c04ac33c0',
time: '2013-02-27 13:51:26'
System info: os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.8.2', java.version: 
'1.6.0_41'
Session ID: cb5a1b7e5f4abc4f2e56e2fe284a9dc3
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{platform=MAC, chrome.chromedriverVersion=26.0.1383.0, acceptSslCerts=false,
javascriptEnabled=true, browserName=chrome, rotatable=false, locationContextEnabled=false,
version=25.0.1364.160, cssSelectorsEnabled=true, databaseEnabled=false, 
handlesAlerts=true, browserConnectionEnabled=false, nativeEvents=true,
webStorageEnabled=true, applicationCacheEnabled=false, takesScreenshot=true}]
blah blah...

I tried adding the contenteditable attribute to my input fields but no luck there:

  <input type="date" contenteditable="true" required="required" placeholder="YYYY-MM-dd" />

I am not sure if I should report that or where to report it but I found these issues in related projects that somewhat similar:

https://github.com/jnicklas/capybara/issues/554

https://github.com/Behat/MinkSelenium2Driver/pull/29

In the meantime any suggestions to get around that bug?

Ren

like image 600
Renaud Avatar asked Mar 12 '13 11:03

Renaud


People also ask

How you will clear data without using a clear method?

2) Press the backspace key but here the number of times backspace key pressed should be equal to the number of character in the string because backspace will clear one character in one press.

How to handle calendar popup in Selenium?

Step 1 - Initiate WebDriver and set the application's URL where a Calendar is implemented. Define the xpath with the Calendar control's id (in this example it is - travel_date) from the html source to find the element and later use that object to initiate the click action.

What is clear method in Selenium?

clear method is used to clear text of any field, such as input field of a form or even to anchor tag paragraph, etc. It replaces its contents on the webpage in your browser.

How do I get the current date in Sendkeys?

findElement(fromDate); } By fromDate= By.id("from"); selenium. selenium-webdriver.


1 Answers

As a workaround you can select the webElement representing the input field and perform a

webElement.SendKeys(Keys.Delete);

to clear the field.

like image 88
Robert Avatar answered Oct 12 '22 00:10

Robert