from selenium import webdriver from pykeyboard import PyKeyboard import time import os k = PyKeyboard() files = os.listdir('H:Report2020') for f in files: dr = webdriver.Firefox() dr.get( 'http://localhost:6868/demo/reportJsp/preview.jsp?__rpx=%2F' + str( f) + '&__rpxHome=E%3A%2FWork%2FdsMin%2FReport2020&__dfxHome=C%3A%2FProgram+Files%2Fraqsoft%2Freport%2Fbin') # dr.get('http://localhost:6868/demo/reportJsp/preview.jsp?__rpx=%2F001%E5%90%84%E7%BA%A7%E5%90%84%E7%B1%BB%E6%95%99%E8%82%B2%E6%A0%A1%E6%95%B0%E3%80%81%E6%95%99%E8%81%8C%E5%B7%A5%E6%95%B0%E3%80%81%E4%B8%93%E4%BB%BB%E6%95%99%E5%B8%88%E6%83%85%E5%86%B5.rpx&__rpxHome=E%3A%2FWork%2FdsMin%2FReport2020&__dfxHome=C%3A%2FProgram+Files%2Fraqsoft%2Freport%2Fbin') aaa = dr.find_element_by_xpath('//*[@class="ICOhover"]') aaa.click() time.sleep(1) bbb = dr.find_element_by_xpath('//*[@class="l-btn-text"]') bbb.click() time.sleep(1) k.press_key(k.down_key) time.sleep(1) k.press_key(k.enter_key) time.sleep(3) dr.close()