Home > OS >  How to type text in input element in Selenium without finding the input element?
How to type text in input element in Selenium without finding the input element?

Time:06-02

I have a python script that uses Selenium and, in the script, a Google Login (OAuth) button is clicked and a new window is displayed as shown below:

New window screenshot

In the new window, thanks to the superb UX :P, the input element for the email field is already selected. Since the field is already selected, can I use Selenium to just start typing without finding the input element and using send_key?

CodePudding user response:

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

Try using action chains to send the keys over.

CodePudding user response:

Just switch to active element .switch_to.active_element :

element = driver.switch_to.active_element
element.send_keys('value')
  • Related