2

I'm trying to automate facebook marketplace posts. But i'm struggling to upload pictures to it.

I already locate the element. When i click the element it will show the 'box' showing the file manager so that i can click on the folders and then the desired image.

ele = wait.until(EC.element_to_be_clickable((By.XPATH,'//*[@id="rc.js_c"]/div/div[1]/div[5]/div[2]/div/div/div/div/div[1]/div/div/span/div/a/div[2]')))
ele.click()

But when i try this:

ele.send_keys('/file_path/rasp.jpeg')

It raises this exception:

selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable

I also tried using the os library:

ele.send_keys(os.getcwd() + '/home/br1/Downloads/rasp.jpeg')

Getting the same exception error.

The html code where the element is visible (element used in code):

<div class="_3jk">

which is the parent of (where the element is not visible):

<input accept="image/*" multiple="" name="composer_photo" title="Elige un archivo para subir" data-testid="add-more-photos" display="inline-block" type="file" class="_n _5f0v" id="js_wg">

Here is all the code if you want to try it:

 from selenium import webdriver
 from selenium.webdriver.chrome.options import Options
 from selenium.webdriver.support import expected_conditions as EC
 from selenium.webdriver.support.ui import WebDriverWait
 from selenium.webdriver.common.by import By 10 
 # driver protocols
 options = Options()
 options.add_argument('disable-notifications')
 options.add_argument('start-maximized')
 driver = webdriver.Chrome(options=options, executable_path='/chromedriver')
 wait = WebDriverWait(driver,10)
 # url
 driver.get('http://facebook.com/marketplace')
 driver.implicitly_wait(10)
 # logging
 driver.find_element_by_id('email').send_keys('username')
 driver.find_element_by_id('pass').send_keys('password')
 driver.find_element_by_id('u_0_2').click()
 # entering marketplace
 driver.find_element_by_xpath('//*[contains(text(), "Vender algo")]').click()
 driver.find_element_by_xpath('//*[contains(text(), "Artículo en venta")]').click()
 ele = wait.until(EC.element_to_be_clickable((By.XPATH,'//*[@id="rc.js_c"]/div/div[1]/div[5]/div[2]/div/div/div/div/div[1]/div/div/span/div/a/div[2]')))
 ele.send_keys('/file_path/rasp.jpeg')

Any ideas and suggestions will be aprecciate it. I'm a Linux user.

2
  • you need to send keys to the input tag. (It'll set the 'value' attribute to your path...) Commented Feb 11, 2020 at 19:05
  • this is same problem with div upload photo ? stackoverflow.com/questions/65268922/… Commented Dec 13, 2020 at 1:40

1 Answer 1

3

You should try using the input to send the file path rather the div.

Try the below.

ele = wait.until(EC.presence_of_element_located((By.XPATH,'//input[@name="composer_photo" and @type="file"]')))
ele.send_keys("file_to_be_uploaded")
Sign up to request clarification or add additional context in comments.

2 Comments

it worked without using os module. Thank you so much.
I've tried all possibilities and only the 'Full XPath' Option worked. Can you tell my why? Result of some Elements: Xpath: <selenium.webdriver.remote.webelement.WebElement (session="3d4555cb39e167485f17a9ac928c0111", element="E58A64FF0AF08BA0AA4EF76EEDE5EB98_element_292")> ID: <selenium.webdriver.remote.webelement.WebElement (session="3d4555cb39e167485f17a9ac928c0111", element="E58A64FF0AF08BA0AA4EF76EEDE5EB98_element_292")> Full Xpath: <selenium.webdriver.remote.webelement.WebElement (session="3d4555cb39e167485f17a9ac928c0111", element="E58A64FF0AF08BA0AA4EF76EEDE5EB98_element_299")>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.