How can I loop a different string into the email field, or a variable without actually having to make a list that consist of 100 different emails. For example is there a way i can send [email protected] to the email field then [email protected] and so on.
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
import unittest
class CreateAccount(unittest.TestCase):
def setUp(self):
global driver
driver = webdriver.Firefox()
driver.implicitly_wait(10)
driver.get("http://www.copy.com")
driver.maximize_window()
def test_main(self):
createNewAccount = driver.find_element_by_xpath("/html/body/main/div/div[1]/div[2]/div/div[2]/div[1]/div/div[2]/div[1]/div/form/div[5]/div[1]/a")
createNewAccount.click()
firstName = driver.find_element_by_xpath("//*[@id='dom_id_3']")
lastName = driver.find_element_by_xpath("//*[@id='dom_id_4']")
emailField = driver.find_element_by_xpath("//*[@id='dom_id_5']")
passwordField = driver.find_element_by_xpath("//*[@id='dom_id_6']")
submitButton = driver.find_element_by_xpath("/html/body/main/div/div[1]/div[2]/div/div[2]/div[1]/div/div[2]/div[2]/div[1]/form/button")
firstName.send_keys("mike")
lastName.send_keys("mano")
emailField.send_keys("[email protected]")
passwordField.send_keys("test12")
submitButton.click()
try:
xpath = driver.find_element_by_xpath("/html/body/main/div/article[2]/div[4]/header/div[2]/div/div[4]/a")
print("Yeah")
except NoSuchElementException:
print("Failed")
raise Exception(NoSuchElementException)
def tearDown(self):
driver.quit()
if __name__ == "__main__":
unittest.main(warnings='ignore')
user3671239user3671239
asked Apr 23, 2015 at 14:55
-
Do you know the email addresses in advance, i.e. are you working from a fixed list? Or could you make up the email addresses in the code?Vince Bowdren– Vince Bowdren2015年04月24日 09:24:14 +00:00Commented Apr 24, 2015 at 9:24
-
I am needing the same thing. I would like my test case to generate a new email id every time it runs. for example, [email protected], then the next time when it runs it should generate [email protected], [email protected] and so on and so forth. Below is my code: int i = 0; for(int count=1; count < 2; i++){ driver.findElement(By.name("signupDialogEmail")).sendKeys("mholmgren" + i + "@gmail.com"); The above code keeps looping and keeps generating ids after ids.user12839– user128392015年07月28日 21:46:31 +00:00Commented Jul 28, 2015 at 21:46
-
Mike, is that intended to be an answer to the question, or are you saying, "Me too!"user246– user2462015年07月29日 01:27:53 +00:00Commented Jul 29, 2015 at 1:27
1 Answer 1
If you're trying to register 100 accounts, this is a simple addition to your code to do that.
for i in range(100):
email_address = "money" + str(i) + "@qa.test"
firstName.send_keys("mike")
lastName.send_keys("mano")
emailField.send_keys(email_address)
passwordField.send_keys("test12")
submitButton.click()
answered Apr 23, 2015 at 16:23
-
This only works once. To get a more unique number, consider using a Unix Time Stamp stackoverflow.com/q/19801727/1106708kirbycope– kirbycope2015年07月29日 03:20:02 +00:00Commented Jul 29, 2015 at 3:20
-
1@kirbycope The question specifically asked for 100 accounts containing a prefix and a number and a domain, starting with number 1. That it only works once also depends on one's teardown methodology. That being said, it's generally a good idea to create unique email addresses since it's not very difficult.Lucas Schwarz– Lucas Schwarz2015年08月20日 03:00:00 +00:00Commented Aug 20, 2015 at 3:00
default