"File",-6ren">
gpt4 book ai didi

ruby - watir 无法定位类型为 "File"的元素

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

页面上的html包含:

<input type="File" name="File" size="70" value="" class="inputfield_en">

我正在尝试使用 ruby​​ (1.9.2) 和 watir-webdriver (0.3.5) 设置值

@browser.file_field(:type=>"File",:name=>"File",:class=>"inputfield_en").to_subtype.set("#{Dir.pwd}/status_feed_for_test.xml")

但是我得到:

   .rvm/gems/ruby-1.9.2-p290/gems/watir-webdriver-0.3.5/lib/watir-webdriver/elements/element.rb:248:in `assert_exists': unable to locate element, using {:type=>"file", :name=>"File", :class=>"inputfield_en", :tag_name=>"input"} (Watir::Exception::UnknownObjectException)

这是因为 html 包含带有大写“F”的文件类型吗? (我无法控制 HTML)。如何修复?

最佳答案

在 watir 中,您只需要指定尽可能多的选择器来唯一标识元素。在这种情况下,您可能只需要 :name

@browser.file_field(:name=>"File")

更新:看来您在 watir-webdriver 中遇到了一个错误,其中 file_field 仅选择一个小写的字段 type="file"。您可能想尝试更通用的选择方法:

@browser.element(:xpath => '//input[@type="File"]')

关于ruby - watir 无法定位类型为 "File"的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8541229/

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