Home > Software design >  Selenium interact with Google Drive
Selenium interact with Google Drive

Time:12-13

I am currently using Selenium to automate the downloading file from public Google Drive folder.

I use browser.find_element(By.CLASS_NAME, "akerZd").click() , but it just opens the browser with Drive page and does not do anything after. ("akerZd" is the name of class of small download button on the folder)

My code:

from selenium import webdriver
from selenium.webdriver.common.by import By

browser = webdriver.Chrome("C:\\chromedriver\\chromedriver.exe")
browser.get('https://drive.google.com/drive/folders/1mOGQW__azsRkJI-l4vFjcxwYO5DC8uEA')
element = browser.find_element(By.CLASS_NAME, "akerZd")
element.click()

How can I do to solve this problems? Have a good day.

CodePudding user response:

wait=WebDriverWait(driver,10)
driver.get('https://drive.google.com/drive/folders/1mOGQW__azsRkJI-l4vFjcxwYO5DC8uEA')
wait.until(EC.presence_of_element_located((By.CLASS_NAME,"akerZd"))).click()
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR,"button[name='ok']"))).click()

To simply download that file wait for the elements to be clickable and induce a click. I would also recommend not using that class name and using another identifier since it might be dynamic and change. If you know what files to get this would work too.

//div[.='NHV-BOOT-2021-800-STANDARD-ISO.zip']/preceding::div[@aria-label='Download' and @role='link'][1]

Imports:

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

enter image description here

  • Related