如果不在 Capybara 中使用 xpath,我无法获得选项值
I can't get option value without using xpath in Cabybara
我再试着解释一下。我必须获得 Arizone 的价值,但我只能通过 xpath 获得它。元素映射为:element :select_cad_state, "#uniform-id_state"
。我不想使用 xpath 获取值 Arkansas,我想使用类似的东西:select_state.send_keys(DATA[:cad_user][:_state])
???..etc..etc..
我想从 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 基于选项元素的字符串内容(而不是值)。正如我在对您之前的问题的回答中发布的那样,这应该是
select_state.select(DADOS[:cad_user][:_state])
如果这对您不起作用,请提供它给您的错误消息。
我再试着解释一下。我必须获得 Arizone 的价值,但我只能通过 xpath 获得它。元素映射为:element :select_cad_state, "#uniform-id_state"
。我不想使用 xpath 获取值 Arkansas,我想使用类似的东西:select_state.send_keys(DATA[:cad_user][:_state])
???..etc..etc..
我想从 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 基于选项元素的字符串内容(而不是值)。正如我在对您之前的问题的回答中发布的那样,这应该是
select_state.select(DADOS[:cad_user][:_state])
如果这对您不起作用,请提供它给您的错误消息。