gpt4 book ai didi

ruby - 在 Watir 中使用 file_field 上传文件时出现问题

转载 作者:数据小太阳 更新时间:2023-10-29 07:37:27 25 4
gpt4 key购买 nike

我的系统:

Windows 10 Pro 64-bit

ruby 2.1.9p490 (2016-03-30 revision 54437) [x64-mingw32]

FireFox 47.0.1

首先,这是我正在处理的代码:

<div class="dz-style col-sm-7" is="null">
<div is="null">You can drag and drop your supporting document files here, or click to select files to upload.</div>
<input style="display: none;" multiple="" is="null" type="file"></div>

这是我的 watir 测试代码:识别并确认文件有效

local_file = '/Users/tom.feodoroff/Desktop/Charlie_Snoopy.jpg'

File.exists? local_file

raise "error" unless File.exists? local_file

更改样式显示以便我可以与控件交互

element = BROWSER.input(:type => 'file')

puts element.attribute_value('style') #display: none;

script = "return arguments[0].style = 'display: inline'"

BROWSER.execute_script(script, element)

puts element.attribute_value('style') #display: inline;

使用建议的语法将文件添加到应用程序

BROWSER.file_field(:type => 'file').set(local_file)

这不会产生任何错误,但它也不会附加文件,因此我的提交按钮变为事件状态。我是否需要不同版本的 Ruby (Watir) 才能完成这项工作,还是我遗漏了什么?

最佳答案

我不明白为什么,但我在单击提交按钮之前添加了 sleep(5),现在它可以工作了。我的文件图标现在出现在页面上并且提交按钮处于事件状态并成功提交了表单。让你走'hmmmm'的事情:)感谢您的回复。希望这会帮助其他人解决这个问题?

关于ruby - 在 Watir 中使用 file_field 上传文件时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38594838/

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