Search code examples
pythondataframeseleniumwebdriver

How to fill the active INPUTs on the page?


I'm having trouble filling in the inputs below:

enter image description here

for link in driver.find_elements(By.CSS_SELECTOR, "input[placeholder='https://www.example.com/']"):
    for index, row in df_links.iterrows():
        print("link")
        link.send_keys((row["link"]))

this way the code repeats the information from the first line of the excel file for all inputs, but I need it to fill in the following sequence:

Input 1 populate with information from line 1

Input 2 populate with information from line 2

and so on, how can I solve this?


Solution

  • In order to access the each row and enter in the each input field, Use Python zip() function and iterate.

    for link,(index,row) in zip(driver.find_elements(By.CSS_SELECTOR, "input[placeholder='https://www.example.com/']"),df_links.iterrows()):
        link.send_keys(row["link"])
    

    zip function reference