【问题标题】:Watir - file_field.exists? comes up as false even though there is an upload form on the pageWatir - file_field.exists?即使页面上有上传表单,也会出现错误
【发布时间】:2012-12-25 00:52:37
【问题描述】:

我正在查看一个包含“选择文件/浏览”等按钮的覆盖网页 下面是页面中的一个sn-p

<form name = "form1" method = "post" action = "UploadPhoto.aspx?PhotoUploaderFor=1" id = "form1" enctype = "multipart/form-data">
<div>...</div>
<div class = "popup-form photoUploader">
 <div class = "group data-row">
  <label>...</label>
  <input type ="file" name = "FileUpload1" id = "FileUpload1" class = "browse_file">

Watir 有 file_fields 可以处理文件上传 我已经在测试站点 (www.tinypic.com) 上进行过尝试,并且控件在那里运行良好

b.file_fields.exists? 

将返回 true

但是,在我使用上面的 sn-p 查看的页面上,

 b.file_fields.exists? 

返回假

我以为可能是形式的原因,所以我也尝试了

b.form(:name => "form1").file_fields.exists?

这也返回 false 如果我尝试直接访问按钮本身,这也会返回 false

b.element(:xpath => "//input [@name = 'FileUpload1']").exists?

有人有什么想法吗?

编辑

表单在 iframe 中

<iframe id="Step1_Banner1_Popup_Photo_Photo_Iframe_PhotoUploader" class="photoUploaderFrame" scrolling="no" src="../MSReport3/UserControls/UploadPhoto.aspx?PhotoUploaderFor=1">
#document
 <!DOCTYPE html PUBLIC "-//W3C//DTD CHTML 1.0 .....">
  <html xmlns = "http://www.w3.org/1999/xhtml">
   <head>...</head>
   <body>
   <code from above goes here>

【问题讨论】:

  • 在本地使用您的 sn-p,browser.file_field(:id =&gt; "FileUpload1").exists? 返回 true。这个页面上可能有框架吗?
  • 嗨@orde,感谢您的关注。上面几个步骤创建了一个 iframe。
  • @orde 感谢您的提醒。即使我可以在 iframe 中找到表单,但不引用它,我想这不适用于所有其他元素。 b.frame(:id => "Step1_Banner_Popup_Photo_Photo_Iframe_PhotoUploader").file_field.exists?返回真
  • 您的问题得到解答了吗?

标签: ruby watir


【解决方案1】:

注意:我从 cmets 发布解决方案,以便(希望)可以将这个问题标记为已回答。

覆盖在一个框架内,需要通过方法链指定框架。例如:

b.frame(:id => "Step1_Banner_Popup_Photo_Photo_Iframe_PhotoUploader").file_field.exists?

【讨论】:

  • 你有一个错字(file_fields 应该是file_field
  • @Jeff 在他的问题中引用了file_fieldsfile_fieldfile_fields 方法都应该在上面的例子中工作。
  • 不,因为file_fields 返回FileFieldCollection 并且它没有#exists? 方法,所以它不起作用。
  • 谢谢@p0deje。我进行了编辑并打算跟进(但分心了)。假设页面有&lt;input type ="file"&gt;browser.file_fields.exists? 的结果将是undefined method exists? for #&lt;Watir::FileFieldCollection:0x312a3c8&gt; (NoMethodError)
猜你喜欢
  • 1970-01-01
  • 2014-04-01
  • 1970-01-01
  • 2016-03-25
  • 1970-01-01
  • 1970-01-01
  • 2016-10-21
  • 2022-01-25
  • 1970-01-01
相关资源
最近更新 更多