【发布时间】:2016-11-22 11:02:04
【问题描述】:
我正在从 Jenkins 运行我的 selenium 脚本,当执行该脚本时,它会在专门用于 Selenium 测试的机器上运行。但我有一个问题。如下所述,我正在使用 Robot 类执行一些操作:
1) 点击图片上传图标。 2) 与 Ubuntu OS 相关的窗口(文件上传)打开。 3)我必须过去图像的位置。 4) 然后点击打开。
所有这些在本地机器上都可以正常工作。但由于 Robot 类的限制,在远程机器上失败。
谁能帮我解决这个问题?
为了更清楚,我附上了一张快照。
<div class="dropify-wrapper">
<div class="dropify-message">
<span class="file-icon"/>
<p>Drag and drop a file here or click</p>
<p class="dropify-error">Sorry, this file is too large</p>
</div>
<input id="category_tile_upload" class="dropify" data-default-file="" type="file"/>
<button class="dropify-clear" type="button">Remove</button>
<div class="dropify-preview">
<span class="dropify-render"/>
<div class="dropify-infos">
<div class="dropify-infos-inner">
<p class="dropify-filename">
<span class="file-icon"/>
<span class="dropify-filename-inner"/>
</p>
<p class="dropify-infos-message">Drag and drop or click to replace</p>
</div>
</div>
</div>
</div>
【问题讨论】:
-
如果您需要将文件上传到网络应用 UI,您可能需要使用
driver.find_element_by_xpath("//input[@type='file']").send_keys(path_to_file)(Python示例)而不是Robot类... -
@Andersson 我没有可以发送密钥的文本框。它不是浏览器元素,所以我无法识别。
-
您正在尝试单击按钮(图标)。我想这个元素(例如
<div class="Upload button">)有嵌入元素<input type="file">,它实际上应该从文件上传对话框中获取值......为您的上传按钮显示HTML -
@Andersson 是的。但现在的问题是我正在使用网格执行测试。当它在远程机器上执行时,本地路径将无效。无论如何这可以处理吗?像我可以使用 getResourceAsStream 吗?
-
Robot使用的测试文件在哪里?您可以设置文件的相对路径
标签: java selenium selenium-webdriver