Search code examples
pythonpython-3.xselenium-webdriverselenium-chromedriver

i'm working on to make a python bot to click button in a list that is repeating it's self using selenium


I want to make a python bot that will do my daily work that i do repeatedly and same work, so for that i'm using selenium with chrome. I want to click a button that repeat it'self but in a list and i could not find a way to click , i tried XPATH but it's not working , it's not even clicking one time and i want to click it on all the list and repeat this process for long it.enter image description here This is the error i'm getting

Traceback (most recent call last): File "c:\Users\rehan\OneDrive\Desktop\python auto\relisiting.py", line 77, in <module> button = WebDriverWait(driver, 30).until(EC.element_to_be_clickable((By.XPATH, button_xpath))).click() 

File "C:\Local\Programs\Python\Python312\Lib\site-packages\selenium\webdriver\support\wait.py", line 105, in until raise TimeoutException(message, screen, stacktrace)
  
selenium.common.exceptions.TimeoutException: Message: Stacktrace: Backtrace: GetHandleVerifier [0x00F9A813+48355] (No symbol) [0x00F2C4B1] (No symbol) [0x00E35358] (No symbol) [0x00E609A5] (No symbol) [0x00E60B3B] (No symbol) [0x00E8E232] (No symbol) [0x00E7A784] (No symbol) [0x00E8C922] (No symbol) [0x00E7A536] (No symbol) [0x00E582DC] (No symbol) [0x00E593DD] GetHandleVerifier [0x011FAABD+2539405] GetHandleVerifier [0x0123A78F+2800735] GetHandleVerifier [0x0123456C+2775612] GetHandleVerifier [0x010251E0+616112] (No symbol) [0x00F35F8C] (No symbol) [0x00F32328] (No symbol) [0x00F3240B] (No symbol) [0x00F24FF7] BaseThreadInitThunk [0x75507BA9+25] RtlInitializeExceptionChain [0x7753C11B+107] RtlClearBits [0x7753C09F+191]

This is the function i used and did not worked

button_xpath="//\[@id='mount_0_0_e+'\]/div/div\[1\]/div/div\[3\]/div/div/div\[1\]/div\[1\]/div\[2\]/div/div/div\[2\]/div\[1\]/div/div\[3\]/div/div/span/div/div/div\[1\]/div/div/div/div\[2\]/div/div\[2\]/div/div\[2\]/div/div/span/div"

button = WebDriverWait(driver, 30).until(EC.element_to_be_clickable((By.XPATH, button_xpath))).click()

These are the tricks i used but not working. I think i'm not doing the XPath the correct way.

This is the HTML of the button

<div aria-label="Relist this item 🅿  AvaiLabLe  📞 For price !" class="x1i10hfl xjbqb8w x1ejq31n xd10rxx x1sy0etr x17r0tee x972fbf xcfux6l x1qhh985 xm0m39n x1ypdohk xe8uvvx xdj266r x11i5rnm xat24cr x1mh8g0r xexx8yu x4uap5 x18d9i69 xkhd6sd x16tdsg8 x1hl2dhg xggy1nq x1o1ewxj x3x9cwd x1e5q0jg x13rtm0m x87ps6o x1lku1pv x1a2a7pz x9f619 x3nfvp2 xdt5ytf xl56j7k x1n2onr6 xh8yej3" role="button" tabindex="0"><div role="none" class="x1n2onr6 x1ja2u2z x78zum5 x2lah0s xl56j7k x6s0dn4 xozqiw3 x1q0g3np xi112ho x17zwfj4 x585lrc x1403ito x972fbf xcfux6l x1qhh985 xm0m39n x9f619 xn6708d x1ye3gou x1qhmfi1 x1r1pt67"><div class="x6s0dn4 x78zum5 xl56j7k x1608yet xljgi0e x1e0frkt"><div role="none" class="x9f619 x1n2onr6 x1ja2u2z x193iq5w xeuugli x6s0dn4 x78zum5 x2lah0s x1fbi1t2 xl8fo4v"><i data-visualcompletion="css-img" class="x1b0d499 xep6ejk" aria-hidden="true" style="background-image: url(&quot;https://static.xx.fbcdn.net/rsrc.php/v3/yz/r/t2GBcB0lq1J.png&quot;); background-position: 0px 0px; background-size: auto; width: 16px; height: 16px; background-repeat: no-repeat; display: inline-block;"></i></div><div role="none" class="x9f619 x1n2onr6 x1ja2u2z x193iq5w xeuugli x6s0dn4 x78zum5 x2lah0s x1fbi1t2 xl8fo4v"><span class="x193iq5w xeuugli x13faqbe x1vvkbs x1xmvt09 x1lliihq x1s928wv xhkezso x1gmr53x x1cpjm7i x1fgarty x1943h6x xudqn12 x3x7a5m x6prxxf xvq8zen x1s688f x1dem4cn" dir="auto"><span class="x1lliihq x6ikm8r x10wlt62 x1n2onr6 xlyipyv xuxw1ft">Relist this item</span></span></div></div><div class="x1ey2m1c xds687c x17qophe xg01cxk x47corl x10l6tqk x13vifvy x1ebt8du x19991ni x1dhq9h x1o1ewxj x3x9cwd x1e5q0jg x13rtm0m" role="none" data-visualcompletion="ignore" style="inset: 0px;"></div></div></div>

Solution

  • for index, button in enumerate(buttons):
        try:
            print(f"Clicking button {index + 1}")
            # Scroll to the button
            scroll_to_element(button)
    
            WebDriverWait(driver, 10).until(EC.element_to_be_clickable(button))
    
            driver.execute_script("arguments[0].click();", button)
            print(f"Button {index + 1} clicked.")
            time.sleep(2) 
        except Exception as e:
            print(f"Failed to click button {index + 1}: {str(e).encode('utf-8', 'ignore')}")