Rahul Rao
Rahul Rao

Reputation: 91

click() doesn't work in selenium

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 !!

Upvotes: 2

Views: 5921

Answers (1)

alecxe
alecxe

Reputation: 474191

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")

Upvotes: 6

Related Questions