我会再解释一遍。我必须得到Arizone的值,但我只能通过xpath得到它。元素已映射为:element :select_cad_state, "#uniform-id_state"
。我不想使用xpath来获得值Arkansas,我想使用类似于:select_state.send_keys(DATA[:cad_user][:_state])
???。。等等。
我想从users.yml文件中获取arizona值,并将其作为前面的参数传递。
############ code page #####################
<div class="selector" id="uniform-id_state" style="width: 269px;"><span style="width: 259px; user-select: none;">Florida</span><select name="id_state" id="id_state" class="form-control" style="">
<option value="">-</option>
<option value="1">Alabama</option>
<option value="2">Alaska</option>
<option value="3">Arizona</option>
<option value="4">Arkansas</option></div>
################### my PageObjects #########################
class ScreenCadastro < SitePrism::Page
set_url 'http://automationpractice.com/index.php?controller=authentication&back=my-account'
element :input_cad_company, "#company"
element :input_cad_address, "#address1"
element :input_cad_city, "#city"
element :select_state, "#uniform-id_state" (my problem is here)
################ yaml file ##############
:cad_user:
:_password: 457226
:_company: SQATest
:_address: International Drive 678
:_city: Bradenton
:_state: Arizona
################## my env file ###################
DADOS = YAML.load(File.open(File.join(File.dirname(__FILE__) + "/massa/users.yml")))
input_cad_company.send_keys(DADOS[:cad_user][:_company])
input_cad_address.send_keys(DADOS[:cad_user][:_address])
input_cad_city.send_keys(DADOS[:cad_user][:_city])
find(:xpath,'/html/body/div/div[2]/div/div[3]/div/div/form/div[2]/p[7]/div/select/option[3]').click
您询问的是选项值,但从所有代码来看,您实际上想要根据选项元素的字符串内容(而不是值(进行选择。正如我在回答你之前的问题时所说的,这应该只是
select_state.select(DADOS[:cad_user][:_state])
如果这对你不起作用,请提供它给你的错误消息。