c# - 在 Selenium 中导入文件
问题描述
页面包含以下内容form
:
<form target="PID297_TGT_FRAME" action="/app/upload/57aa897a64d9" class="form form-default" method="post" enctype="multipart/form-data">
<div>
<input type="hidden">
<input name="PID297_file" class="file-upload" type="file">
<div aria-pressed="false" role="button" class="v-button" tabindex="0">
<span class="v-button-wrap">
<span class="v-button-caption">Import</span>
</span>
</div>
</div>
</form>
现在我想将文件上传到表单。在搜索 stackoverflow 后,我发现可以input
使用 type发送文件路径file
。所以我这样做了:
var elem = Driver.FindElement(By.Name("PID297_file")).SendKeys(filePath);
不幸的是,我收到Exception
了消息:
Element is not currently visible and so may not be interacted with
我的代码有问题吗?
解决方案
该元素需要对 selenium 可见才能访问它。如果有其他动作可以启用文件上传,请先在 selenium 代码中执行。
推荐阅读
- android - 在片段中,使用 Parcelable 实现恢复包含另一个对象列表的对象
- windows - 无法在 Windows 上使用 LLVM 库
- firebase - Firebase 安全规则从另一个节点获取值并将其与 auth.uid 进行比较
- javascript - 在 reactjs 中编辑数组
- php - Laravel 邮件事件有一个空消息
- android - 如何将提示属性转换为 ViewModel 中的观察项
- sql - 内部连接的 SQL 列单独显示?
- oracle - PLS-00103:在预期以下情况之一时遇到符号“)”:(
- java - 如果在没有 JMSPriority 标头的情况下发送 JMS 消息会发生什么
- html - 与 NavBar 位于同一行的 FontAwesome 图标