找到带有watir的span id

时间:2013-01-18 17:58:42

标签: watir

在网站上,有一个字段由用户填充,方法是单击“浏览”按钮,然后选择文件。我无法弄清楚如何填充它。几年前我们运行了测试用例,它是browser.fileField(:id,"file01").set(x)发现的,但不再有效。

irb(main):154:0>  bowser.fileField(:id,"file01").exists?
NoMethodError: undefined method `fileField' for #<Watir::IE:0x35de4d8>
        from (irb):154
        from C:/Ruby193/bin/irb:12:in `<main>'

我可以找到它,但未能比这更远:

irb(main):159:0> browser.form(:id, '104').span(:id, "file_1").exists?
=> true

这是代码:

<form id="104" onsubmit="return validateForm();" method="post" >
<input type="hidden" value="1" name="create">
<input id="external" type="hidden" value="0" name="external">
<table class="text fullWidth" cellspacing="0" summary="Sending Form">
<tbody>
<tr>
<script type="text/javascript">
<tr>
<tr>
<tr>
<tr>
<td class="fRequired">
<td class="fText">
<table class="fInput">
<tbody>
<tr>
<td>
<span id="file_01">
<input id="file01" class="fFile" type="file" onchange="writename(this.value, shortfile1'); return true;" tabindex="2" name="file01">
<span id="shortfile1"> aby.JPG</span>
</span>
<br>
<span id="file_02">
<br>

1 个答案:

答案 0 :(得分:1)

试试这个:

browser.file_field(:id => "file01").set(x)

为了将来参考,watir-classic gem的API在这里:http://rdoc.info/gems/watir-classic