2

i am currently using selenium with python and my webdriver is firefox i tried the click event but it doesn't work

website = www.cloudsightapi.com/api

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.common.exceptions import TimeoutException
import time
from selenium.webdriver.common.action_chains import ActionChains

import os
driver = webdriver.Firefox()
driver.get("http://cloudsightapi.com/api")

wait = WebDriverWait(driver, 10)
element = wait.until(EC.element_to_be_clickable((By.ID, "dropzoneTarget")))
element.click()

Please help !!

1 Answer 1

6

Clicking via javascript worked for me:

element = wait.until(EC.element_to_be_clickable((By.ID, "dropzoneTarget")))
driver.execute_script("arguments[0].click();", element)

Now, the other problem is that clicking that element would only get you into more troubles. There will a file upload popup being opened. And, the problem is, you cannot control it via selenium.

A common way to approach the problem is to find the file input and set it's value to the absolute path to the file you want to upload, see:

In your case, the input is hidden, make it visible and send the path to it:

element = wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, "input.dz-hidden-input[type=file]")))

# make the input visible
driver.execute_script("arguments[0].style = {};", element)
element.send_keys("/absolute/path/to/image.jpg")
Sign up to request clarification or add additional context in comments.

8 Comments

thanks for your help ! send_keys() are not working is there any way to drag and drop the image from local computer ?
@RahulRao no way to drag and drop to the browser with selenium only. About send_keys - what do you mean by not working? (worked for me for a sample jpg image) Thanks.
i mean in my case send_keys() are not working as you mentioned that "input" is hidden , which i can't change ! what you suggest now ?
@RahulRao I've provided a way to make the input visible and then send the keys - works for me. Have you tried that? Thanks.
@eugene glad to see it helped. But please be aware what is the difference between the regular click and "javascript" click.
|

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.