Search code examples
pythonpandaskey

send keys using a condition python


I want to create a loop through which, I send as keys,each value of column A and once value is sent, I send as keys the value from the correspondent row in column B then continue with next value in column A and so on.I column B I may have more then a value on row, separated by space

ID = df['A'] .to_list()
for l in ID:
    myElement.send_keys(l)  ## this will send as keys, value from column A

Next thing will be to send as keys the correspondent value(same row) in column B for each l in column A.

Is there a way to create this condition?

enter image description here

Considering the example df, steps should be send value1 then cavo, then lampada. Send value2, then cavo, then lampada


Solution

  • Use itertuples(). Then you can access each column that you want to send in the loop.

    for row in df.itertuples():
        for word in row.A.split():
            myElement.send_keys(word)
        for word in row.B.split():
            myElement.send_keys(word)