Home > Back-end >  Is there a way to automatically input text in the different text box using Python Selenium?
Is there a way to automatically input text in the different text box using Python Selenium?

Time:10-04

I wanted to test a registration form with a lot of text boxes.
Instead of manually using the .sendkeys() to each text box, is there a way to automatically input texts into each and every textbox in the page?

CodePudding user response:

You may use page factory to store the locators and use from there every time or you can try the Data/Text driven framework also.

CodePudding user response:

If I understand your question correctly, you'd like to have as little lines of code as possible for a form of text boxes with each their individual xpaths?

A way to do this you could use a list of xpaths (and text), which you iterate through and fill in automatically.

Note, you'd probably want to add a WebdriverWait to wait for the element to be loaded on the screen but this snippet might help you on your way.

# list of tuples consisting of a xpath and text to fill in that textbox
my_list = [('//*[@id="textbox_email"]', '[email protected]'), ('//*[@id="textbox_password"]', 'pwd123'), (..., ...)]

for xpath, text in my_list:
    driver.find_element_by_xpath(xpath).send_keys(text)

  • Related