gpt4 book ai didi

ruby - capybara 找不到要附加文件的文件输入字段

转载 作者:数据小太阳 更新时间:2023-10-29 08:18:15 26 4
gpt4 key购买 nike

我用 ruby 、 cucumber 和 capybara 。

我的 html 看起来像这样:

     <tr>
<th>
Promotion codes
</th><td><div class="t-zone" id="promocodesZone">
<span style="display: inline-block;">
<span class="field"><label class="field-label">File name:
<span style="text-transform: none;" class="status-ok"></span></label></span>
<span class="field"><label class="field-label">Codes available:
<span style="text-transform: none;" class="status-ok">0</span></label></span>
<span class="field"><label class="field-label">Codes used:
<span style="text-transform: none;" class="status-ok"></span></label></span>
<span class="field"><label class="field-label">Codes uploaded on:
<span style="text-transform: none;" class="status-ok"></span></label></span>
</span>
<div style="margin-bottom: 15px;"><div class="t-upload">
<div id="promocodesUpload">
<div class="qq-uploader">
<div class="qq-upload-drop-area" style="display: none;"><span>Drop </span></div>
<a class="qq-upload-button btn" style="position: relative; overflow: hidden; direction: ltr;">Upload
<input type="file" name="file" style="position: absolute; right: 0px; top: 0px; font-family: Arial; font-size: 118px; margin: 0px; padding: 0px; cursor: pointer; opacity: 0;"></a>
<ul class="qq-upload-list"></ul></div></div>
</div>
</div>
</div>
</td>
</tr>

基本上我需要做的是通过点击“上传”链接来上传文件:

<a class="qq-upload-button btn" style="position: relative; overflow: hidden; direction: ltr;">Upload<input type="file" name="file" style="position: absolute; right: 0px; top: 0px; font-family: Arial; font-size: 118px; margin: 0px; padding: 0px; cursor: pointer; opacity: 0;"></a>

但我一直失败,因为 capybara 无法找到必要的元素......我已经尝试了很多东西:

attach_file('//*[@id="promocodesUpload"]/div/a/input', File.absolute_path($campaign_promotional_code_path))

结果:无法找到文件字段“//*[@id=\"promocodesUpload\"]/div/a/input"(Capybara::ElementNotFound)

within(:xpath, '//*[@id="promocodesUpload"]/div/a') do
attach_file("input", File.absolute_path($campaign_promotional_code_path))
end

结果:无法找到文件字段“input”(Capybara::ElementNotFound)

attach_file("Upload", File.absolute_path($campaign_promotional_code_path)

结果:找不到文件字段“上传”(Capybara::ElementNotFound)

click_link("Upload")

结果:无法找到“上传”链接(Capybara::ElementNotFound)

有什么帮助吗? :)

最佳答案

试试这个:

page.driver.browser.all(:xpath, '//input[@name="file"]')[0].send_keys('/home/userA/Desktop/chivalry-medieval-warfare.jpg')

或:

page.driver.browser.all(:xpath, '//input[@type="file"]').last.send_keys('/home/userA/Desktop/chivalry-medieval-warfare.jpg') 

关于ruby - capybara 找不到要附加文件的文件输入字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32986393/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com