[英]Calling a Select_List with Watir-Webdriver Without an ID/Name
[英]watir select_list regex variable NoValueFoundException
Ruby新手,需要一些幫助。 將變量傳遞給select_list,我想找到與該變量匹配的第一個選項。
列表選項是:
...然后我將城市分配給變量
var="Portland"
使用: f.select_list(:id => /location/).select(/var/)
給出NoValueFoundException
但是當我使用...
`f.select_list(:id => /location/).select(/Portland/) #no exception, gives 1st entry`
如何使用正則表達式和變量訪問第一個選項?
與使用文字正則表達式/ var /相比,您需要從變量var的字符串值構造正則表達式。
例:
:001 > /hello/.match('hello world')
=> #<MatchData "hello">
:002 > exp = 'hello'
=> "hello"
:003 > /exp/.match('hello world')
=> nil
:004 > Regexp.new(exp).match('hello world')
=> #<MatchData "hello">
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.