Send keys without specifying element in python selenium webdriver
38,118
Solution 1
solved it
from selenium.webdriver.common.action_chains import ActionChains
actions = ActionChains(self.driver)
actions.send_keys('dummydata')
actions.perform()
Solution 2
If you get error about 'self' in this code:
from selenium.webdriver.common.action_chains import ActionChains
actions = ActionChains(self.driver)
actions.send_keys('dummydata')
actions.perform()
just use:
actions = ActionChains(driver)
I don't have comment rights that's why I put this as answer
Edit: Added this enhancement as a comment on the original answer.
Solution 3
This worked for me:
driver.find_element_by_tag_name('body').send_keys(' ')
(Which I used to use a space character to scroll through a page)
Author by
Saurabh Shrivastava
Updated on August 27, 2020Comments
-
Saurabh Shrivastava over 3 years
I have a page whose source code is not available, but there is a input box where cursor is blinking.
Can i write something into the text box without finding the element. I mean, some way where send key can automatically look for focussed inputbox and type input to it.
My code does not work obviuosly
driver.send_keys("testdata")
-
Ayush Mandowara over 3 yearsUse
actions = ActionChains(driver)
if you face issues on line 2 of the above answer. The author probably has the driver generated within a class object, hence needed self.driver to access it.