简体   繁体   中英

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

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 = "xyz@gmail.com,abc@gmail.com"
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 = ["xyz@gmail.com","abc@gmail.com"]
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!

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 = "xyz@gmail.com,abc@gmail.com"
#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)

UPDATE: SOLUTION FOUND

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM