我想通过点击Chrome浏览器上的下载图标来下载文件。 我尝试了几种方法,比如Xpath和CSS,但都不起作用。请让我知道是否有任何解决方案,在这方面使用Python3.x和硒。你知道吗
下面是我尝试过的代码
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
import time
class TEAutomation:
def automateTask(self):
chromeOptions = Options()
chromeOptions.add_experimental_option("prefs",{"download.default_directory": "/home/vishal/Documents/PythonProgram/"})
baseUrl = "https://www.te.com/commerce/DocumentDelivery/DDEController?Action=showdoc&DocId=Customer+Drawing%7F160743%7FM2%7Fpdf%7FEnglish%7FENG_CD_160743_M2.pdf%7F160743-1"
driver = webdriver.Chrome(executable_path="/home/vishal/PycharmProjects/VSProgramming/drivers/chromedriver",chrome_options=chromeOptions)
driver.maximize_window()
driver.get(baseUrl)
driver.implicitly_wait(10)
driver.find_element(By.XPATH,'//*[@id="download"]').click()
#driver.find_element(By.CSS_SELECTOR, '#download').click()
time.sleep(5)
driver.quit()
molexAuto = TEAutomation()
molexAuto.automateTask()
先谢谢你。你知道吗
当您尝试单击该元素时,可能该元素仍未加载,请尝试使用
WebDriverWait
等待它,我没有chrome,因此您必须自己进行测试:相关问题 更多 >
编程相关推荐