Unable to add multiple email addresses to sendkeys() while using Selenium

562 Views Asked by At

Unable to add multiple email addresses to sendkeys() while using Selenium. What I'm trying to do is send an email to multiple addreses using selenium remote webdriver to build some test cases.

The below logic only sends the email to the first recipient.

email = "[email protected],[email protected]"
driver.find_element_by_name("to").send_keys(email)

The below logic executes fine without throwing any exception but it does not generate the email at all.

emails = ["[email protected]","[email protected]"]
for email in emails:
    time.sleep(5) #to wait for the element to be interactable
    driver.find_element_by_name("to").send_keys(email)

Could someone please guide in the right direction? Thanks!

2

There are 2 best solutions below

0
On BEST ANSWER

UPDATE: SOLUTION FOUND

The email addresses require space in between and it works just fine without looping.

4
On

It’s convenient to use loop if you want to add multiple emails but i am not sure what exactly you are trying to do here, but simple solution could be

emails = "[email protected],[email protected]"
#split funtion will convert string into list split wrt “,”
emails =emails.split(',')
for email in emails:
   driver.find_element_by_name("to").send_keys(email)