0

I'm using R and RSelenium to get some data from a website, for which I have to fill in a form first. One of the elements I have to define in the form is a date.

The box containing the date has the following html code:

<input readonly="readonly" name="Datei" id="Datei" onfocus="popUpCalendar(this, this,'dd/mm/yyyy');return false" maxlength="10" value="" style="width: 200px;" type="text">

I want to set that date to jan 01/2016, or 01/01/2016 to go with the required format.

After getting to the element with

webElem <- rd$findElement("id","Datei")

I've tried these two approaches, but none of them worked (because the item is "readonly", I think):

webElem$value <- list("01/01/2016")

and

webElem$sendKeysToElement(list("01/01/2016"))

As suggested here, I tried

webElem$executeScript(script = "arguments[1].value=arguments[2]",args = list(webElem,"01/01/2016"))

Error:   Summary: UnexpectedAlertOpen
 Detail: A modal dialog was open, blocking this operation
 class: org.openqa.selenium.UnhandledAlertException

I'm running out of ideas, any hint is highly appreciated!

EDIT TO ADD

I found (and posted) an answer. I would like to know, though, if somebody knows of a better approach (using httr, for instance).

Community
  • 1
  • 1
PavoDive
  • 6,322
  • 2
  • 29
  • 55
  • @lukeA it's a Colombian government site that holds all purchasing needs by the gov: https://www.contratos.gov.co/consultas/inicioConsulta.do . The field's name is fechaInicial (initial date). – PavoDive Jan 19 '16 at 20:51

1 Answers1

1

Looking deeper into selenium examples, I found this pearl: (translated to R)

  rd$executeScript("document.getElementById('Datei').removeAttribute('readonly',0);")
  dt <- rd$findElement("id","Datei")
  dt$clearElement()
  dt$sendKeysToElement(list("01/01/2016"))

which worked very well. Leaving it here, in case somebody stumbles upon the same need.

Community
  • 1
  • 1
PavoDive
  • 6,322
  • 2
  • 29
  • 55