0
webdriver = webdriver.Chrome("C:/Users/acer/chromedriver_win32/chromedriver.exe")
url = 'http://biokb.ncpsb.org/AllerGAtlas/index.php/Home/Browse/?fbclid=IwAR2RPwrnsT7zR9SEdU0PW-eJ7HAelg6WRyn23-hCjTrNCEOb1uOMd_qG3ns'
webdriver.get(url)
webdriver.save_screenshot('test.png')
webdriver.find_elements_by_class_name('fa fa-download').click()
#webdriver.find_element_by_xpath('//*[@class="fa fa-download"]').click()

I want to download all the files available.

The error I got :

InvalidSelectorException: Message: invalid selector: Compound class names not permitted (Session info: headless chrome = 73.0.3683.103) (Driver info: chromedriver = 2.45.615291 (ec3682e3c9061c10f26ea9e5cdcf3c53f3f74387), platform=Windows NT 10.0.17134 x86_64)

3 Answers3

1

You can avoid .click and concatenate the name onto base url and .get which will download all. Specify path to chromedriver if not on environmental path.

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

base = 'http://biokb.ncpsb.org/AllerGAtlas/index.php/Home/Download/gene/genesymbol/'
d = webdriver.Chrome()
d.get('http://biokb.ncpsb.org/AllerGAtlas/index.php/Home/Browse/?fbclid=IwAR2RPwrnsT7zR9SEdU0PW-eJ7HAelg6WRyn23-hCjTrNCEOb1uOMd_qG3ns')
links = [base + item.text for item in  WebDriverWait(d,10).until(EC.presence_of_all_elements_located((By.CSS_SELECTOR, "#geneTable td:nth-of-type(1)")))]
for link in links:
    d.get(link)
d.quit()
QHarr
  • 83,427
  • 12
  • 54
  • 101
0

You are using find_elements which will return a list of web element. You can not invoke click() method on it.

click() method is for web element.

instead try this code :

all_links = webdriver.find_elements_by_class_name('fa fa-download')
for link in all_links:
  link.click()
cruisepandey
  • 28,520
  • 6
  • 20
  • 38
0
webdriver.find_elements_by_class_name('fa fa-download').click()

Please note find_elements returns list so you should use find_element instead. However when you use find_element_by_class_name you can't provide mutliple class name which gives you error as you can see your error message.so try follwoing code.

webdriver.find_element_by_class_name('fa-download').click()

OR

webdriver.find_elements_by_class_name('fa-download')[0].click()

OR you can use css selector.

webdriver.find_elements_by_css_selector('.fa.fa-download')[0].click()

EDITED

Try induce webdriverwait to identify element and then clicks either options.

from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By   

elements=WebDriverWait(driver,30).until(EC.visibility_of_all_elements_located((By.CSS_SELECTOR,'.fa.fa-download')))

elements[0].click()

OR

elements=WebDriverWait(driver,30).until(EC.visibility_of_all_elements_located((By.CSS_SELECTOR,'.fa.fa-download')))
ActionChains(driver).move_to_element(elements[0]).click().perform()
KunduK
  • 32,888
  • 5
  • 17
  • 41