Python Selenium chrome headless无法在Linux服务器上执行onclick事件

Python Selenium chrome headless无法在Linux服务器上执行onclick事件,python,linux,selenium,google-chrome,selenium-chromedriver,Python,Linux,Selenium,Google Chrome,Selenium Chromedriver,我在将Python Selenium无头google chrome脚本从Windows移植到Linux服务器(该服务器可导航到网站并下载文件)时遇到问题。脚本在windows和linux服务器上运行时没有错误,但是linux服务器上的脚本从不下载文件 我不知道可能是什么问题。我认为这可能是权限问题,但我使用wget包运行了一个小脚本,它将文件下载到指定的文件夹中 您认为是什么原因阻止同一脚本在linux服务器上下载文件?服务器安装了最新的chrome和chromedriver版本81,我的程序正

我在将Python Selenium无头google chrome脚本从Windows移植到Linux服务器(该服务器可导航到网站并下载文件)时遇到问题。脚本在windows和linux服务器上运行时没有错误,但是linux服务器上的脚本从不下载文件

我不知道可能是什么问题。我认为这可能是权限问题,但我使用wget包运行了一个小脚本,它将文件下载到指定的文件夹中

您认为是什么原因阻止同一脚本在linux服务器上下载文件?服务器安装了最新的chrome和chromedriver版本81,我的程序正确地指向它们

此脚本工作并下载图标

此脚本运行并关闭驱动程序,但当指向本地计算机上的正确文件夹时,不会在我的个人计算机上的Windows中下载任何ThingWorks。没有脚本中断错误,因为它的下载位置与上面的脚本相同,所以我认为这不是权限问题。这两个脚本都是从同一个文件夹执行的

from selenium import webdriver
print('packages imported')
from selenium.webdriver.chrome.options import Options
print('options imported')

#specifying headless and download options

options = Options()
options.add_argument('--headless')
options.add_argument('--disable-gpu') 

driver = webdriver.Chrome(executable_path=r'team/mm/chromedriver', options=options)


#'/external/gen_dir'  directory for sample data

params = {'behavior': 'allow', 'downloadPath': r'/external/gen_dir'}
driver.execute_cdp_cmd('Page.setDownloadBehavior', params)
print('download paramaters executed')

driver.get("https://www.thinkbroadband.com/download")

# initialize an object to the location on the html page and click on it to download
search_input = driver.find_element_by_css_selector('#main-col > div > div > div:nth-child(8) > p:nth-child(1) > a > img')
search_input.click()

driver.quit()
print('driver closed')


这似乎是因为driver.quit在下载开始之前运行,所以

search_input.click()
time.sleep(5)

driver.quit()

请您使用javascript执行器在该元素上执行一次单击。嗨,Philippe。成功了。我想问你,为什么你会认为在我的Windows机器上,我不需要设置睡眠计时器,但必须添加到Linux服务器上的脚本中?你原来的脚本在Windows上也不适用于我,所以我很难找到答案。你能再检查一下它在Windows上是否有效吗?嗨,Philippe,我可以解释为什么它在我的电脑上有效。我把它写在Jupyter笔记本上,driver.quit行在一个单独的单元格中,所以当我运行不同的Jupyter单元格时,我无意中延迟了执行。但是如果我把所有的代码放在一个单元格中,那么windows也不会下载任何东西。这就解释了。你仍然需要找到一种比time更健壮的方法。例如,对于更大的文件,sleep5。我知道。我需要写一个检查来延迟操作,直到下载文件夹中的文件号增加1,并且可能检查文件是否已完全下载。谢谢你的帮助
search_input.click()
time.sleep(5)

driver.quit()