splinter icon indicating copy to clipboard operation
splinter copied to clipboard

Cannot send characters directly to the browser

Open LewisW opened this issue 2 years ago • 1 comments

The documentation implies that you can send keys directly to the browser, but the code expects an element name to be provided.

The result is an error like the following: TypeError: BaseWebDriver.type() missing 1 required positional argument: 'value'

Is this something that's still supported?

LewisW avatar Mar 19 '23 19:03 LewisW

From what I understand, the way to do this is as below.

from selenium.webdriver.common.keys import Keys
from splinter import Browser
from splinter.driver import webdriver

browser = Browser("firefox")
browser.visit("https://github.com")
driver = browser.driver
actions = webdriver.ActionChains(driver)
# Queue for effect only. The first / brings up the search bar,
# the others type the search query in the search bar, followed by
# Enter to submit the form.
send_keys = ["/", "cobrateam", "/", "splinter", Keys.ENTER]
for send in send_keys:
    actions.send_keys(send)

actions.perform()

The function (implementation for web drivers) could be edited to run this code if no name argument is provided. But the function signature would not allow a default to just be set for name without value also having a default. Changing this would be a breaking change and affect some implementations.

More info from Stack Overflow.

Thus I agree, the documentation is misleading re this.

nameloCmaS avatar Feb 24 '24 22:02 nameloCmaS

Awesome, thanks for clarifying.

LewisW avatar May 16 '24 08:05 LewisW