In the example app you provided, focus stays on the email input. You can check it using code below:
driver.get("https://boxing-registration.herokuapp.com/")
email = driver.find_element_by_id("email-input")
email.send_keys("lala")
active_element = driver.execute_script("return document.activeElement")
print(active_element.get_attribute("outerHTML"))
assert active_element == email
You can try to use ActionChains
, example:
ActionChains(driver).send_keys_to_element("lala").click(dropdown_list).perform()
I have an HTML <input>
field which produces autocomplete suggestions as the user types. I would like to make an automated test where the Selenium driver inputs some keys and then checks the contents of the autocomplete dropdown. The problem is that if I use the Selenium send_keys
method, the <input>
loses focus and the dropdown disappears. Is there a way to enter keys into an <input>
element without losing the focus?
I made a minimalistic example:
from selenium import webdriver
class TestLogin():
def setup_method(self, method):
self.driver = webdriver.Chrome()
self.vars = {}
def teardown_method(self, method):
self.driver.quit()
def test_minimalistic_registration(self):
self.driver.get("https://boxing-registration.herokuapp.com/")
self.driver.find_element_by_id("email-input").send_keys("lala")
print("done")
You can put a breakpoint on the last line and see that the focus of the <input>
element is lost.
@RobMoll unfortunately no. As soon as focus is lost, the autocomplete functionality is off.
Thank you! I tried to switch to Firefox and it worked. Switched back to Chrome and now it works on Chrome as well. Must be a bug on my side.