Problem with action chains in interation using selenium and click()

21 Views Asked by At

i'm new to Python and i'm trying to build a automatic better in Roulette for training purpose. For now, i've a good setup and everything is fine. I'm passing a "result" object to my function handle_bet_placing This object is like: {token25: 3, token5: 0, token2: 1, token1: 1, token0_5: 0, token0_2: 0} for a total amount of 78. After that, i select every token, click on it, and should be able to click 'quantite' times on the betting spot. Problem is while i'm iterating in my click_category function like : for i in range(quantite): click_on_bet_spot('red') I'm facing a problem. When quantite is 1 it's ok it click 1 time. But when it's 2, I'm facing an extra click and it's clicking 3 times..

Any clue why ?

Thank you for your help guys !

def click_on_bet_spot(element_id):
    try:
        element = driver.find_element(By.XPATH, f'//*[@data-bet-spot-id="{element_id}"]')
        action = ActionChains(driver)
        action.move_to_element(element).click().perform()
    except Exception as e:
        logger.error(f"Error clicking on element with data-bet-spot-id='{element_id}': {str(e)}")
def click_on_token(value):
    try:
        css_selector = f".chip--768ce[data-value='{value}']"
        element = driver.find_element(By.CSS_SELECTOR, css_selector)
        action = ActionChains(driver)
        action.move_to_element(element).click().perform()
        action.reset_actions()
        time.sleep(0.2)
    except Exception as e:
        logger.error(f"Error finding element with data-bet-spot-id='{value}': {str(e)}")
def handle_bet_placing(result, bet):
    for token, quantite in result.items():
        if quantite > 0:
            if token == 'token25':
                click_on_token(25)
                click_category(quantite, bet)
            if token == 'token5':
                click_on_token(5)
                click_category(quantite, bet)
            if token == 'token2':
                click_on_token(2)
                click_category(quantite, bet)
            if token == 'token1':
                click_on_token(1)
                click_category(quantite, bet)
            if token == 'token0_5':
                click_on_token(0.5)
                click_category(quantite, bet)
            if token == 'token0_2':
                click_on_token(0.2)
                click_category(quantite, bet)
def click_category(quantite, bet):
    if bet['Type'] == 'Red':
        for i in range(quantite):
            click_on_bet_spot('red')
    elif bet['Type'] == 'Black':
        for i in range(quantite):
            click_on_bet_spot('black')
    elif bet['Type'] == 'Odd':
        for i in range(quantite):
            click_on_bet_spot('odd')           
    elif bet['Type'] == 'Even':
        for i in range(quantite):
            click_on_bet_spot('even')
    elif bet['Type'] == 'High':
        for i in range(quantite):
            click_on_bet_spot('from19to36')
    elif bet['Type'] == 'Low':
        for i in range(quantite):
            click_on_bet_spot('from1to18')

I did try already without actions reset, but still not working

0

There are 0 best solutions below