I have a program that uses selenium. In this program I have a tkinter GUI with a listbox.
The list box that can be filled with names by entering the name in the entry field and adding it with a button.
After I filled my list I want to go over each name and perform a search loop.
this is my code so far (tried to simplify it for this example):
def loop_player_listbox():
global bol_loop
bol_loop = True
if bol_loop is True:
time.sleep(1)
str_libo = listbox.get(0, tk.END)
for i in str_libo:
text_playername = wait.until(EC.element_to_be_clickable((By.XPATH,('/html/body/main/section/section/div[2]/div/div[2]/div/div[1]/div[1]/div[1]/div/input'))))
text_playername.clear()
text_playername.click()
text_playername.send_keys(i)
try:
choose_player = wait.until(EC.element_to_be_clickable((By.XPATH,("//span[@class='btn-text' and contains(text(),'"+i+"')]"))))
choose_player.click()
except:
print('Player not found!')
example()
In this example I want to go over each item in the list, search for the name on a URL and click it if the name was found and popped up in a specific xpath.
After that, and thats what I cant get done right, I want to perform a function in a loop. The function should loop 5 times and then it should go over to the next na,e in my list box, and do the same (so actually for all names in my box it should perform this 5x times)
This is the loop to be performed:
def example(int_user_input_max_price, int_choose_speed): # buy only routine
# start buy only mode
global start_process, exit_tool
exit_tool = False
start_process = True
if start_process is True:
time.sleep(1)
btn_search = driver.find_element_by_xpath('/html/body/main/section/section/div[2]/div/div[2]/div/div[2]/button[2]')
# set max price
ipt_max_price = driver.find_element_by_xpath(
ipt_max_price.click()
time.sleep(1)
ipt_max_price.send_keys(int_user_input_max_price)
time.sleep(1)
# Set min price
int_min_price = 150
# Set max players bought
int_max_players_bought = 100
int_players_bought = 0
# Buy until 100 players were bought
while int_players_bought < int_max_players_bought:
else:
I don't go over the meaning of all my code, I just need to know, how could I make it possible that this example() is getting executed 5 times then go back to the next item in my listbox?
If any further input is needed pls let me know. Tried to not spam too much of my code.
Ps.: I am a beginner as u might see.. ;-)
Aucun commentaire:
Enregistrer un commentaire