Python - Selenium send_keys() does not work in this form field

Asked

Viewed 1,042 times

3

I made the correct identification with xPath, the software . clear() works perfectly, however send_keys does not work at all. Follow the HTML code of the form:

<input id="yui-gen19" name="e_dt_ini_0" size="12" value="01/06/2015" class="dw-params43C55" 
tabindex="1" style="position: absolute; left: 3.49in; top: 0in; width: 0.967in; height: 0.197in;" 
onfocus="{dw_params.itemGainFocus(0,10,this,dw_params.gobs.e_dt_ini); dw_params.selectControlContent(this);}" 
onclick="{var ret;  ret= dw_params.itemClicked(0,10,'e_dt_ini',0,-1); return ret;}" 
onchange="{this.bChanged = true;}" onkeypress="return DW_EditKeyPressed(event, this, -1);" 
onblur="{dw_params.itemLoseFocus (this);}" type="text">

Everything else works perfectly. This form field is unbearable even for direct user filling.

The code in Python:

 # Preenche o Formulário
    hoje = datetime.datetime.strftime(datetime.datetime.now(), '%d/%m/%Y')
    dataInicioXpath = "//*[@id='dw_params_detail_0']/input[4]"
    dataFimXpath = "//*[@id='dw_params_detail_0']/input[3]"
    medicoXpath ="//*[@id='dw_params_detail_4']/input[3]"
    relButtonXpath = "//*[@id='bt_emitir']"


    dataInicioElement = WebDriverWait(driver, 15).until(lambda driver: driver.find_element_by_name("e_dt_ini_0")) # find_element_by_xpath(dataInicioXpath))
    dataFimElement = WebDriverWait(driver, 15).until(lambda driver: driver.find_element_by_xpath(dataFimXpath))
    medicoElement = WebDriverWait(driver, 15).until(lambda driver: driver.find_element_by_xpath(medicoXpath))
    relButtonElement = WebDriverWait(driver, 15).until(lambda driver: driver.find_element_by_xpath(relButtonXpath))


    dataInicioElement.click()
    dataInicioElement.clear()
    dataInicioElement.send_keys(hoje)
    dataFimElement.click()
    dataFimElement.clear()
    dataFimElement.send_keys(hoje)
    medicoElement.clear()
    medicoElement.send_keys("11111")
    relButtonElement.click()
  • 1

    Shows identification with xPath

  • Ah, it would be nice if you told us if he’s inside a <iframe>.

  • 1

    Esse campo do formulário é insuportável até para o preenchimento direto pelo usuário. I managed to fill in the hand

2 answers

1

You have already tried to pass this value via javascript?

webdriver.execute_script("document.getElementById('yui-gen19').value = '"+hoje+"'")
  • Gave this error: Selenium.common.exceptions.Webdriverexception: Message: Document.getElementById(...) is null

0

Why not select directly by id?

campo = driver.find_element_by_css_selector('#yui-gen19')
  • I have tried several ways. The field identification works well on all of them. What doesn’t work is key_send. The field is boring until it is filled in manually. You type the numbers of the day and it jumps alone the month.

  • Have you tried putting one time.sleep(0.5) for each character typed?

  • 1

    I tried to fill in with only 1 character and he did not accept. I will try with team.sleep. Thank you =)

  • Didn’t work either.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.