프로그래밍/python
input[type=file] 태그에 파일을 업로드 하는 방법
이휘재123
2022. 9. 6. 15:55
반응형
# send_keys로 업로드 시도
uploader = driver.find_element(By.CSS_SELECTOR, "#file_upload")
uploader.send_keys('your_file')
time.sleep(1)
만약 하나의 태그에 복수개의 파일이 들어가는 multiple 속성을 갖고있다면 반드시 input 태그를 clear 해준 후에 send_keys를 사용해야한다.
그렇지 않으면 이전에 올린 파일의 기록이 남아있어서 그 이전 파일들이 한번 씩 더 업로드 된다.
my_files = ['file1', 'file2', 'file3']
uploader = driver.find_element(By.CSS_SELECTOR, "#file_upload")
for my_file in my_files:
uploader.clear()
uploader.send_keys(my_file)
반응형