java - 如何使用 xpath 作为 sendkeys 从 selenium 上传只读文本文件将不起作用
问题描述
这是结构:
<input _ngcontent-c9="" class="form-field" placeholder="Upload Emote" readonly="" type="text">
我已使用以下代码上传文件,但 sendkeys 不起作用,我没有收到任何错误但无法上传。
WebElement uploadingEmote = adminDriver.findElement(By.xpath("//input[@placeholder='Upload Emote']"));
uploadingEmote.sendKeys("/home/smart/Downloads/EMO/(Heart).png");
但是上面的代码不起作用,因为该字段是只读的。任何帮助,将不胜感激。
解决方案
<input _ngcontent-c9="" class="form-field" placeholder="Upload Emote" readonly="" type="text">
如果要上传文件,您的输入字段类型应为“文件”类型
<input type="file" name="fileToUpload" id="fileToUpload">
推荐阅读
- javascript - Google 数据存储实体创建和更新
- css - div垂直对齐中心与相对位置
- material-ui - material-ui / 如何使用 'withStyles()' 设置 HOC 样式?
- c# - 使用 WITH MOVE 标识文件的有效位置。例外
- selenium - Selenium C#如何获取元素
- azure - 用于容器状态存储的 Azure Web App
- mysql - 删除时 SQL 触发器实现反向级联
- android - 运算符 != 不能应用于 double、null
- html - 将 HTML 内容导入其他 HTML 页面
- javascript - redux.js:91 未捕获的错误:期望减速器是一个函数