Python Forum
not abel to run selenium automation one by one in loop
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
not abel to run selenium automation one by one in loop
#1
HELLO, i just learned python and this is my first project.
everything is working fine except looping part. if amount is 10 and i have 2 automation site functions. so as loop starts, loop count 1 and site function should be 1 and as as loop count 2 so site function 2 should start but its not working like that. as the loop starts site 1 function repeating 10 times then it goes to site 2 function, i dont want like this. i want to make it, 1 count = site 1 function, count 2 = site 2 function should work. PLEASE HELP. THANK YOU.

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time

mobile_number = '9199999999'
amount = 10

chrome_options = webdriver.ChromeOptions()
prefs = {"profile.default_content_setting_values.notifications" : 
chrome_options.add_experimental_option("prefs",prefs)
browser = webdriver.Chrome(chrome_options=chrome_options)

def decathlon(mobile_number):         #SITE 1 FUNCTION
    for i in range(amount):        
        browser.get('https://www.decathlon.in/')
        time.sleep(2)        
        login = browser.find_element_by_class_name('m-0').click()
        time.sleep(1)
        number = browser.find_element_by_class_name('floating-input').send_keys(mobile_number)         
        button = browser.find_element_by_class_name('decabutton').click()      
        time.sleep(2)                   
        #browser.quit()

def shaze(mobile_number):         #SITE 2 FUNCTION
    for i in range(amount): 
        browser.get('https://www.shaze.in/customer/account/create/')
        time.sleep(2)
        number = browser.find_element_by_class_name('mobnumber').send_keys(mobile_number)
        time.sleep(1)         
        otp = browser.find_element_by_class_name('regi-sendotp').click()      
        time.sleep(2)         
        #browser.quit()

for i in range(amount):  # LOOP for repeating automation
    shaze(mobile_number)
    decathlon(mobile_number)
Reply
#2
OK, I'm getting kind of confused while reading your post. So mayby I do not fully understand it well.

Are you saying that both of the site functions should NOT run 10 times, but just once? Because both of the functions are exactly implying that: a loop that is running 10 times.
- Everybody is a genius. But if you judge a fish by its ability to climb a tree, it will live its whole life believing that it is stupid. Albert Einstein
Reply
#3
(Apr-25-2020, 06:49 PM)Jeff900 Wrote: OK, I'm getting kind of confused while reading your post. So mayby I do not fully understand it well.

Are you saying that both of the site functions should NOT run 10 times, but just once? Because both of the functions are exactly implying that: a loop that is running 10 times.

if i said loop to run 10 times, then the loop should run 10 times but 1 by 1,

(1). if loop starts from 1 then site 1 function should run and when loop reach count 2 then site 2 function should start.

(2). but the loop not working like that, if i said to run 10 times then site 1 function runing 10 times then it going to site 2 function, it should work like (1).
Reply
#4
OK, maybe you can use an if statement that will look if i (from the loop) is odd or even. You can use modulus for that.

if i % 2 == 0: 
    # execute function 2 
else:
    # excute function 1
If you can't figure this concept, find some info about modulus.
- Everybody is a genius. But if you judge a fish by its ability to climb a tree, it will live its whole life believing that it is stupid. Albert Einstein
Reply
#5
(Apr-25-2020, 07:07 PM)Jeff900 Wrote: OK, maybe you can use an if statement that will look if i (from the loop) is odd or even. You can use modulus for that.

if i % 2 == 0: 
    # execute function 2 
else:
    # excute function 1
If you can't figure this concept, find some info about modulus.

its still not working, same thing happening, every function repeating 2 times, i dont want like that. i want it to work like, 1 function should work once then it should go to other function.
Reply
#6
I that case you should share the output you get, and explain where it is going wrong. Explain what output you expect. That will probably makes it a lot easier to understand the problem.
- Everybody is a genius. But if you judge a fish by its ability to climb a tree, it will live its whole life believing that it is stupid. Albert Einstein
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Selenium Chromedriver Automation Help lessthanthree 1 2,142 May-05-2020, 11:03 PM
Last Post: Larz60+
  Error in Selenium: CRITICAL:root:Selenium module is not installed...Exiting program. AcszE 1 3,618 Nov-03-2017, 08:41 PM
Last Post: metulburr
  Python Selenium Document Lookup and Download Automation Error - Target Machine active Guttmann 4 5,193 Apr-18-2017, 12:13 AM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020