#creating a function to loop threw 1 item on list at a time in python using selenium

7 messages · Page 1 of 1 (latest)

dire valve
#

for example id like to run threw a list 1 item at a time meaning, that it executes first item on list = index[0], continues to run the rest of the program then come back to loop with login and access second item on list index [1]. So on and so forth.

this is code>>>

def login():

email_group1 = ["*****","*****",""]
pass_group1 = ["*****","*****",""]

#click login btn
loginbtn1 = driver.find_element("xpath", "/html/body/section[1]/div/div/div/div[2]/a[2]")
loginbtn1.is_displayed()
loginbtn1.click()

login email

time.sleep(1)
login_email = driver.find_element("name", "email")
login_email.is_displayed()

for email in email_group1:

    login_email.send_keys(email)


login_pass = driver.find_element("xpath", "/html/body/div[1]/div/div/div/form/div[2]/input")
login_pass.is_displayed()

for password in pass_group1:

    login_pass.send_keys(password)
#

login email has a hash before it like this

#

#login email

last lagoon
#

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time

Sample array of users

user_array = ["user1", "user2", "user3", "user4", "user5"]

Set up the Selenium webdriver (make sure to replace 'path/to/chromedriver' with your actual path)

driver_path = 'path/to/chromedriver'
driver = webdriver.Chrome(executable_path=driver_path)

Dummy action function (replace this with your actual action)

def perform_dummy_action(user):
# For this example, let's just print the user
print(f"Performing dummy action for user: {user}")

# You can add your actual actions here

Loop through the array of users

for user in user_array:
# Open a dummy website (replace 'http://example.com' with your actual URL)
driver.get('http://example.com')

# Perform the dummy action for the current user
perform_dummy_action(user)

# Add a delay (replace 2 with your desired delay in seconds)
time.sleep(2)

Close the webdriver

driver.quit()

#

If I have my understanding correct this should work when you're trying to execute your action once per user

thin halo
#

!format

rich oasisBOT
#
Code Formatting

When sharing code with the community, please use the correct formatting for ease of readability.

Example

```py
YOUR CODE HERE
```

Those are back ticks not single quotes, typically the key above TAB