1

I'm trying to upload a picture inside a button, but I keep getting this error:

selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
(Session info: chrome=79.0.3945.130)

This is my code

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait

import time
import os

driver = webdriver.Chrome()
driver.get("https://easypdf.com/fr/convertir-ocr")
driver.maximize_window()

time.sleep(10)
driver.find_element_by_xpath('//*[@id="social"]/div/div[1]').click()

uploadPhotoBtn = driver.find_element_by_xpath('//*[@id="dzupload"]/div')
driver.execute_script('arguments[0].style = ""; arguments[0].style.display = "block"; arguments[0].style.visibility = "visible";', uploadPhotoBtn)
uploadPhotoBtn.send_keys("C:\\Users\\basma\\Desktop\\python\\toImg\\jpg0.jpg")
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Lara
  • 23
  • 6

1 Answers1

0

To upload image for conversion within the website https://easypdf.com/fr/convertir-ocr using Selenium you need to:

  • Locate the <input> tag where you have to invoke send_keys()
  • Change the value of type attribute from hidden to text
  • Invoke send_keys()
  • Code Block:

    from selenium import webdriver
    
    options = webdriver.ChromeOptions() 
    options.add_argument("start-maximized")
    options.add_experimental_option("excludeSwitches", ["enable-automation"])
    options.add_experimental_option('useAutomationExtension', False)
    driver = webdriver.Chrome(options=options, executable_path=r'C:\Utility\BrowserDrivers\chromedriver.exe')
    driver.get("https://easypdf.com/fr/convertir-ocr")
    element = driver.find_element_by_xpath("//input[@id='tool-name']")
    driver.execute_script("document.getElementById('tool-name').setAttribute('type','text')")
    element.click()
    element.clear()
    element.send_keys(r'C:\Users\Debanjan.B\Desktop\screenshots\31_07_2019.png')
    
  • Browser Snapshot:

image_upload


Update

It would be a bit tough to upload an image file for further processing as the webpage https://easypdf.com/fr/convertir-ocr is protected by Invisible reCAPTCHA.

<div class="rc-anchor rc-anchor-invisible rc-anchor-light  rc-anchor-invisible-hover"><div id="recaptcha-accessible-status" class="rc-anchor-aria-status" aria-hidden="true">Veuillez valider le test reCAPTCHA.. </div><div class="rc-anchor-error-msg-container" style="display:none"><span class="rc-anchor-error-msg" aria-hidden="true"></span></div><div class="rc-anchor-normal-footer smalltext" aria-hidden="true"><div class="rc-anchor-logo-large" role="presentation"><div class="rc-anchor-logo-img rc-anchor-logo-img-large"></div></div><div class="rc-anchor-pt"><a href="https://www.google.com/intl/fr/policies/privacy/" target="_blank">Confidentialité</a><span aria-hidden="true" role="presentation"> - </span><a href="https://www.google.com/intl/fr/policies/terms/" target="_blank">Conditions</a></div></div><div class="rc-anchor-invisible-text"><span>protection par <strong>reCAPTCHA</strong></span><div class="rc-anchor-pt"><a href="https://www.google.com/intl/fr/policies/privacy/" target="_blank">Confidentialité</a><span aria-hidden="true" role="presentation"> - </span><a href="https://www.google.com/intl/fr/policies/terms/" target="_blank">Conditions</a></div></div></div>

Hence, when you try to click the button for conversion, you will face the as follows:

  • Code Block:

    driver.get("https://easypdf.com/fr/convertir-ocr")
    element = driver.find_element_by_xpath("//input[@id='tool-name']")
    driver.execute_script("document.getElementById('tool-name').setAttribute('type','text')")
    element.click()
    element.clear()
    element.send_keys(r'C:\Users\Debanjan.B\Desktop\screenshots\31_07_2019.png')
    driver.find_element_by_xpath("//button[@id='btnUpload']").click()
    
  • Browser Snapshot:

invisible_reCAPTCHA

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • 1
    thank you @DebanjanB for your answer, it's working but in this case we upload only text, and I need to upload the image in order to convert it, can you help me with this please? – Lara Feb 03 '20 at 14:44
  • @Lara Of coarse Stackoverflow contributors are here to help you out. Feel free to raise a new question with your new requirement please. – undetected Selenium Feb 03 '20 at 14:46
  • I still can't upload the image, I can only upload the name of the image, and when I'm trying toc convert it, it says that no file is selected, I don't know how can I fixe that, help me please – Lara Feb 03 '20 at 14:57
  • @Lara Are you seeing any error? Can you please raise a new question with the error you are facing? – undetected Selenium Feb 03 '20 at 15:03
  • @Lara Checkout the answer update and let me know the status – undetected Selenium Feb 04 '20 at 09:09
  • it's not about the recaptcha, it's the file we are uploading, it's like we are uploading a text not an image – Lara Feb 04 '20 at 09:33
  • @Lara The answer caters to the requirement of _uploading_ a document to the site, which I have demonstrated. Can't comment on _text_ or _png_ or _jpg_ as I am not native _French_. – undetected Selenium Feb 04 '20 at 09:37
  • I don't know if you understand me, but what I mean that the problem is not being able to upload the image, we upload only the name of it not all the image – Lara Feb 04 '20 at 10:17
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/207168/discussion-between-lara-and-debanjanb). – Lara Feb 04 '20 at 10:25