如何将文本发送到不可见的输入字段 [英] How to send text to invisible input field

查看:69
本文介绍了如何将文本发送到不可见的输入字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要自动上传文件.

以下是HTML代码,用于指向文件的路径输入字段和用于手动上传的按钮:

Here is a HTML code for path-to-file input field and button for manual uploading:

<div class="ctrl_div">
     <input id="fileupload" class="hid" name="files" accept="application/zip" data-url="/Server/file/upload" type="file">
     <button id="fileBtn" class="btn btn-primary" type="button">Upload</button>
</div>

当我尝试

driver.find_element_by_xpath('//input[@id="fileupload"]').send_keys(path_to_file)

我得到ElementNotVisibleException

我也尝试过

driver.execute_script("document.getElementById('fileupload').style.visibility = 'visible';")

但是对于webdriver,输入字段仍然不可见.

But input field remains invisible for webdriver.

有什么想法吗?

P.S.添加隐式/显式等待不会成功

P.S. Adding implicit/explicit wait will not make a trick

推荐答案

您应该尝试

driver.execute_script(document.getElementById('fileUpload').style.display='bloc‌​k';");

这篇关于如何将文本发送到不可见的输入字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆