How to make while loop for example 5 automatic registration account this is my code and I want to make an automatic python script for 5 registration account

from selenium import webdriver

driver = webdriver.Chrome("C:\chromedriver_win32\chromedriver.exe")

driver.find_element_by_css_selector('div.page-columnMain > form > div.form-group > #email').send_keys("test@test.com")
driver.find_element_by_css_selector('div.form-group.form-group--half > #password').send_keys("test2");
  • for example i want username:test1,test2,test3,test4 password:test234 and for 4 different mails in my example test1@test.com test2@test.com test3@test.com... – breakfast_club Jul 7 '18 at 13:59

Create a method to perform the registration operation just like in the code below. Store the test data as you have mentioned in the comment above in some data-structure or file.

fanme | lname | email | username | password

fanme | lname | email | username | password

Call the below method for each test data.

private void perform_registration(Registration _reg) {
// your webdriver interaction goes here -- something like this
    // other operation continues

This nothing to do with Selenium, this is plain simple language construct; how you organize your code, so that you get properly re-usable code which is easy to maintain.

  • I made like you show me txt file , and save like data.txt how to put in my program for my example up stare? i have in txt fname, lname, email, pass, repeat pass ? – breakfast_club Jul 8 '18 at 19:10
  • fname|lname|email|pass how to make this prog with while loop? – breakfast_club Jul 8 '18 at 19:12
  • Just an observation: The underscore on the argument and the getX methods names are not pythonic. Simply reg and get_file / get_name / get_email is the way. – João Farias Jul 8 '18 at 20:55
  • First you have to read the external txt file and then retrieve the values separating by '/'. Now what you have is your test data in some python object. Pass them to your tests by a data provider(pytest or unittest has this mechanism - data driven testing). – Kshetra Mohan Prusty Jul 9 '18 at 5:10
  • The fname,lname etc are attributes of Registration object if you follow the above example. So you will be passing that object to your test method. Now you have the control how many number of times you want to run that method. – Kshetra Mohan Prusty Jul 9 '18 at 5:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.