0

I have a script in which I click a button and the cursor begins blinking. All my attempts at specifying the element via xpath/id/class name to send the keys from have failed. So, I am attempting to just send the keys to where the cursor is blinking.

I've tried a few solutions:

  1. Send keys without specifying element in python selenium webdriver
from selenium.webdriver.common.action_chains import ActionChains

actions = ActionChains(driver)
actions.send_keys('dummydata')
actions.perform()

This solution did not send any keys at all.

  1. Switch to the active element.
elem = driver.switch_to.active_element()
elem['value'].send_keys('dummydata')
#OR#
elem.send_keys('dummydata')

In this instance, I received error:

elem = driver.switch_to.active_element()
TypeError: 'WebElement' object is not callable

Not sure what else to try at this point. Baffled at why this is happening.

Yu Na
  • 112
  • 1
  • 18
  • Check if the element is inside an `iframe`, if so, [switch to it](https://stackoverflow.com/questions/44834358/switch-to-an-iframe-through-selenium-and-python?rq=1) before sending the keys. – Pedro Lobito Apr 19 '20 at 00:07
  • Try `elem = driver.switch_to.active_element` -- that is, don't use the `()` at the end. – user697473 Apr 27 '20 at 17:44

1 Answers1

1

One reason could be, that the element may inside an iframe as @Pedro is mentioning.

To get the active element without XPath and other selectors, you can try using javascript:

elem = driver.executeScript("document.activeElement")

If this still does not work, it's either an iframe or maybe a virtual software textinput (js, canvas, ...). You can play around with some javascript commands in the browser console to check how and what elements are responding.

Arakis
  • 849
  • 5
  • 16