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.

2
  • Check if the element is inside an iframe, if so, switch to it before sending the keys. Commented Apr 19, 2020 at 0:07
  • Try elem = driver.switch_to.active_element -- that is, don't use the () at the end. Commented Apr 27, 2020 at 17:44

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

1

This worked for me through a modal. I was successfully able to click a button inside a modal.

time.sleep(3)
driver.execute_script("document.activeElement")
time.sleep(3)
send=driver.find_element(By.XPATH,"//button[@aria-label='Send now']")
time.sleep(3)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.