无法使用xpath设置file_field元素

时间:2013-09-09 16:17:51

标签: xpath selenium-webdriver

Html代码如下:

<li>
   <form action="/en/pune/dsf/media/create" enctype="multipart/form-data" method="post">
    <div style="margin: 0px; padding: 0px; display: inline;">
      <input name="authenticity_token" type="hidden" value="DD9PUpCMWTGs66fHEZutO+9RFjcf68xH+T9DMXv1JnA="/>
    </div>
    <div class="media_upload_submit">
      <span class="icon-camera"/>
     <span class="al">Add photos</span>
    </div>
      <input class="media_image_file" data-track="photo_upload,spot_page,user" name="media[image]" type="file"/>
  </form>
</li>

我尝试过使用

@browser.file_field(:xpath, "//input[@type='file' and @class='media_image_file']/").set "Complete file path name"

但是我收到以下错误:

Failure: Unable to locate an element with the xpath expression //input[@type='file' and @class='media_image_file']/ because of the following error:

我尝试过多种不同的方式,但会遇到不同的错误。

1 个答案:

答案 0 :(得分:2)

/之后还有一个..and @class='media_image_file']/"。删除它并写成:

 @browser.file_field(:xpath, "//input[@type='file' and @class='media_image_file']")