我有这样的 HTML:
<a id="buttonToUpload" class="btn-pink medium" href="#">
<span class="icon-arrow-right">upload photo</span>
</a>
<form id="form1" enctype="multipart/form-data">
<input id="uploadImage" type="file" accept="image/png, image/gif, image/jpeg, image/jpg" style="visibility: hidden">
</form>
按引发系统对话框来选择文件,我无法通过网络驱动程序访问该文件。
我尝试直接使用 send_keys() 但它引发了 ElementNotVisibleException。那么我怎样才能在那里上传照片呢?
实际代码:
driver = webdriver.Firefox()
driver.get('http://www........')
upload_input = driver.find_element_by_id('uploadImage')
upload_input.send_keys(os.getcwd()+'/image.jpg')
解决了这个:
driver.execute_script("document.getElementById('uploadImage').style.visibility='visible'")
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)