LambdaTest Community

Find answers, support, and inspiration from other users

Questions
LambdaTest Community
Answered

Typing Enter/Return key using Python and Selenium?

I'm looking for a quick way to type and Enter or Return key in Selenium. Unfortunately the form I'm trying to test (not my own code so I can't modify) doesn't have a Submit button. When working with it manually, I just type ENTER or RETURN. I need to know how to do that with the Selenium type command as there is no button to click.

Up Vote Down Vote 0 Votes
Posted 5 months ago

Answers


Now that Selenium 2 has been released, it's a bit easier to send an Enter key, since you can do it with the send_keysmethod of the selenium.webdriver.remote.webelement.WebElement class (this example code is in Python, but the same method exists in Java):

>>> from selenium import webdriver
>>> wd = webdriver.Firefox()
>>> wd.get("http://localhost/example/page")
>>> textbox = wd.find_element_by_css_selector("input")
>>> textbox.send_keys("Hello World\n")
Up Vote Down Vote 0 Votes
Posted 5 months ago
226 Views
1 Answer
5 months ago