html 웹 페이지에서 testfile을 다운로드하기 위해 셀레늄을 사용하려고합니다. 여기에 테스트 개체로 사용 된 전체 HTML 페이지입니다 : 내가 testzip.zip
로 변경 몇 가지 예를 zip
파일과 함께, 현재 작업 디렉토리에 넣어셀렌으로 zip 파일을 다운로드 할 수없는 이유는 무엇입니까?
<!DOCTYPE html>
<html>
<head>
<title>Testpage</title>
</head>
<body>
<div id="page">
Example Download link:
<a href="testzip.zip">Download this testzip</a>
</div>
</body>
</html>
.
profile = webdriver.FirefoxProfile()
profile.set_preference("browser.download.dir", "/tmp")
profile.set_preference("browser.download.folderList", 2)
profile.set_preference("browser.download.manager.showWhenStarting", False)
profile.set_preference("pdfjs.disabled", True) profile.set_preference("browser.helperApps.neverAsk.saveToDisk","application/zip")
profile.set_preference("plugin.disable_full_page_plugin_for_types", "application/zip")
browser = webdriver.Firefox(profile)
browser.get('file:///home/path/to/html/testweb.html')
browser.find_element_by_xpath('//a[contains(text(), "Download this testzip")]').click()
을 그러나, 나는 (예 : nosetest
로) 테스트를 실행하면 브라우저가 개방하지만 아무 일도 발생하지 않습니다 이후되고, 다음과 같이
내 셀레늄 코드가 보인다. 오류 메시지가 나타나지 않으며 다운로드도되지 않습니다.
이 문제를 해결하는 방법에 대한 아이디어가 있으십니까?
URL이 원인 일 수 있습니다. 일반 http 서버를 사용하여 사이트를 호스팅 한 다음 테스트하십시오. 'python -m SimpleHTTPServer' 그리고'http : // localhost : 8000/testweb.html'을 테스트하십시오 –
그래, 고마워. 하지만 불행히도 나는 실제 문제를 해결하기 위해 더 가까이 있지 않습니다. 다른 비공개 웹 페이지의 경우 유사한 다운로드 링크가 있기 때문에 여기서는 작동하지 않습니다. – Alex