'Selenium|Python Exception: "element not interactable" when uploading product images to wordpress

I am writing code that automatically uploads products to wordpress.

I use selenium (100.0.4896.88) with python (3.10).

I need to upload 2 types of product images (use the same code):

  1. Production image

  2. product gallery images

2 types of product images

1. Set product image (first code)

  #1  open upload frame 
    driver.find_element_by_id("set-post-thumbnail").click()  #Click "set product image"
    time.sleep(10 ) #waiting open frame
    
  #2  open "dialog browser window"  
    driver.find_element_by_id("menu-item-upload").click() #Click tab "upload file"**-->CLICK OK**
    driver.find_element_by_class_name("browser.button.button-hero").click() #open "dialog browser window"
    time.sleep(5) #waiting dialog window open
    
  #3 Send path file   
    pyautogui.write(product_image_path)
    pyautogui.press('enter')
    time.sleep(60 )#waiting upload image
    
  #4 add image
    driver.find_element_by_class_name("button.media-button.button-primary.button-large.media-button-select").click()
    time.sleep(10)

2. Add product gallery images(second code - same the first code)

  #1  open upload frame 
    driver.find_element_by_class_name("add_product_images.hide-if-no-js").click()#Click "Add product gallery images"
    time.sleep(10)#waiting open frame
    
  #2  open "dialog browser window"  
    driver.find_element_by_id("menu-item-upload").click() #Click tab "upload file" ***--> CAN'T CLICK***
    driver.find_element_by_class_name("browser.button.button-hero").click() #open "dialog browser window"
    time.sleep(5) #waiting dialog window open

  #3 Send path file     
    pyautogui.write(gallery_images_path) #path of File
    pyautogui.press('enter')    
    time.sleep(60)#waiting upload image
    
  #4 add image    
    driver.find_element_by_class_name("button.media-button.button-primary.button-large.media-button-select").click()

Click tab "upload file"

With both types of images, use the same upload frame. The code for the 2 uploads is the same.

When uploading "Production image" (the first code) it works fine but the 2nd time uploading :"product gallery images" (the second code) doesn't work. Selenium can't click to tab "Upload file".

driver.find_element_by_id("menu-item-upload").click() #Click tab "upload file"

Exception:

raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
  (Session info: chrome=100.0.4896.88)
Stacktrace:
Backtrace:
        Ordinal0 [0x00C17413+2389011]
        Ordinal0 [0x00BA9F61+1941345]
        Ordinal0 [0x00A9C520+836896]
        Ordinal0 [0x00ACA1F3+1024499]

I tried running these 2 codes separately, they both work fine.

I also changed the location of the 2 codes but it only works for the first code, the second one doesn't work.

I have added win wait driver , use Queryselector or XPATH but they are not working.

WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, '//button[text()="Upload files"]'))).click() 

Please help me. Thank !



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source