Search code examples
pythonfunctionseleniumsendkeys

send_keys from a function in Python and Selenium


I have this function:

def add_key():
    driver.find_element_by_name('key').send_keys('first_bonus')
    driver.find_element_by_name('translation').send_keys('First Bonus')

...

add_key()

Now I want to be able to send_keys and rename them in the future ('first_bonus' and 'First Bonus') when calling the function itself add_key() not inside the function. But I don't want the send_keys("") to be visible when caling the function, just the name of the key and translation. Is it possible?


Solution

  • I guess you need to make it dynamic with arguments

    def add_key(element_name, text):
        driver.find_element_by_name(element_name).send_keys(text)
    add_key('key','first_bonus')