skip to Main Content

I am trying to upload files automatically with selenium in python to the website.
I succesfully added file to the library but stucked on the point where I the script should click ‘Use this file’ button:

screenshot from wordpress

I tried to use

driver.find_element_by_xpath('//*[@id="__wp-uploader-id-0"]/div[4]/div/div[2]/button').click()

but nothing happens.

tried also use actions:

actions = ActionChains(driver)
Element = driver.find_element_by_xpath('//*[@id="__wp-uploader-id-0"]/div[4]/div/div[2]/button')
actions.move_to_element(Element).click().perform();

but also no luck

Do you have any idea what else can I try?

3

Answers


  1. Chosen as BEST ANSWER

    OK it's solved, I had to add time wait until page is loaded fully.

    Closing case


  2. The simplest way is to use this:

    driver.find_element_by_xpath("//button[contains(text(),'Use this file')]").click()
    
    Login or Signup to reply.
  3. if this //*[@id="__wp-uploader-id-0"]/div[4]/div/div[2]/button

    represent a single entity in DOM, you can probably use it with expicit waits :

    wait = WebDriverWait(driver, 10)
    wait.until(EC.element_to_be_clickable((By.XPATH, "//*[@id="__wp-uploader-id-0"]/div[4]/div/div[2]/button"))).click()
    

    having said that, I would still suggest you to use a relative xpath.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search