无法使用watir在salesforce中找到元素

时间:2016-01-28 23:21:58

标签: ruby watir watir-classic

问题1: 输入:

browser.span(:id => 'ProdSelectionPage_Fav:mainform:pbmain:pSecId:j_id90:txtQuoteDesc').when_present.exist?

错误:

C:/Ruby200/lib/ruby/gems/2.0.0/gems/watir-classic-4.2.0/lib/watir-classic/wait.rb:29:in `until': timed out after 60 seconds (Watir::Wait::TimeoutError)
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/watir-classic-4.2.0/lib/watir-classic/element_extensions.rb:18:in `method_missing'
from C:/WebAutomation/Tests/sandbox/attach.rb:52:in `<main>'

问题2: 输入:

browser.frame.text_field(:id, /ProdSelectionPage_Fav:mainform:pbmain:pSecId:j_id90:txtQuoteDesc/).when_present.set'gautam raj'

错误:

C:/Ruby200/lib/ruby/gems/2.0.0/gems/watir-classic-4.2.0/lib/watir-classic/wait.rb:29:in `until': timed out after 60 seconds (Watir::Wait::TimeoutError)
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/watir-classic-4.2.0/lib/watir-classic/element_extensions.rb:18:in `method_missing'
from C:/WebAutomation/Tests/sandbox/attach.rb:56:in `<main>'

没有&#39; when_present&#39;并使用了“睡眠30&#39;前

输入:

browser.frame.text_field(:id, /ProdSelectionPage_Fav:mainform:pbmain:pSecId:j_id90:txtQuoteDesc/).set'gautam raj'

//试过&#39; name&#39;而不是&#39; id&#39;输入

错误:

C:/Ruby200/lib/ruby/gems/2.0.0/gems/watir-classic-4.2.0/lib/watir-classic/element.rb:338:in `assert_exists': Unable to locate element, using {:tag_name=>["frame", "iframe"]} (Watir::Exception::UnknownFrameException)
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/watir-classic-4.2.0/lib/watir-classic/frame.rb:21:in `document'
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/watir-classic-4.2.0/lib/watir-classic/frame.rb:52:in `__ole_inner_elements'
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/watir-classic-4.2.0/lib/watir-classic/locator.rb:204:in `each_element'
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/watir-classic-4.2.0/lib/watir-classic/locator.rb:229:in `each'
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/watir-classic-4.2.0/lib/watir-classic/locator.rb:217:in `locate'
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/watir-classic-4.2.0/lib/watir-classic/input_elements.rb:20:in `locate'
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/watir-classic-4.2.0/lib/watir-classic/element.rb:335:in `assert_exists'
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/watir-classic-4.2.0/lib/watir-classic/element.rb:484:in `perform_action'
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/watir-classic-4.2.0/lib/watir-classic/input_elements.rb:252:in `set'
from C:/WebAutomation/Tests/sandbox/attach.rb:56:in `<main>'

html代码:

<input name="ProdSelectionPage_Fav:mainform:pbmain:pSecId:j_id90:txtQuoteDesc" id="ProdSelectionPage_Fav:mainform:pbmain:pSecId:j_id90:txtQuoteDesc" type="text" size="20" maxlength="35">

2 个答案:

答案 0 :(得分:0)

这里的问题是你试图定位的元素永远不会被watir看到。

因此,对于when_present,它会因Watir::Wait::TimeoutError错误而失败。如果要单击/设置元素不可见,它将失败并显示Watir::Exception::UnknownFrameException错误。

答案 1 :(得分:0)

这里的问题是,当我转到下一页时,系统会抛出错误。所以,当我想转到下一页时,我使用了以下命令

browser = Watir::Browser.attach(:url, //) 

现在,它工作正常