Send keys without specifying element in python selenium webdriver

空扰寡人 提交于 2020-05-09 20:31:05

问题


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")

回答1:


solved it

from selenium.webdriver.common.action_chains import ActionChains
actions = ActionChains(self.driver)
actions.send_keys('dummydata')
actions.perform()



回答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




回答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)



来源:https://stackoverflow.com/questions/32886927/send-keys-without-specifying-element-in-python-selenium-webdriver

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!