Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby 如何从没有[]方括号的选择列表中获取所选选项的文本_Ruby_Watir_Watir Webdriver_Page Object Gem_Rspec Expectations - Fatal编程技术网

Ruby 如何从没有[]方括号的选择列表中获取所选选项的文本

Ruby 如何从没有[]方括号的选择列表中获取所选选项的文本,ruby,watir,watir-webdriver,page-object-gem,rspec-expectations,Ruby,Watir,Watir Webdriver,Page Object Gem,Rspec Expectations,我使用next命令获取选择列表中所选选项的文本: @sltedStudy=page.select_list_element(:id => 'cntrStudy', :frame => frame).selected_options(&:text) 但当我尝试比较价值观时: expect(page.cell_element(:xpath => "//td[.='Lorem Ipsum']/following-sibling::td[1]", :frame => f

我使用next命令获取选择列表中所选选项的文本:

@sltedStudy=page.select_list_element(:id => 'cntrStudy', :frame => frame).selected_options(&:text)
但当我尝试比较价值观时:

expect(page.cell_element(:xpath => "//td[.='Lorem Ipsum']/following-sibling::td[1]", :frame => frame).text).to be == @sltedStudy
它返回:

RSpec::Expectations::ExpectationNotMetError: expected: == ["SLC"]
     got:    "SLC"

如何从没有[]方括号的选择列表中获取文本值?

它看起来像这一行:

@sltedStudy = page.select_list_element(:id => 'cntrStudy', :frame => frame).selected_options(&:text)
提供所选选项中的文本数组:
[“SLC”]

尝试将您的rspec更改为:

expect(page.cell_element(:xpath => "//td[.='Lorem Ipsum']/following-sibling::td[1]", :frame => frame).text).to be == @sltedStudy.first
或者这个:

expect([page.cell_element(:xpath => "//td[.='Lorem Ipsum']/following-sibling::td[1]", :frame => frame).text]).to be == @sltedStudy

看起来是这样的:

@sltedStudy = page.select_list_element(:id => 'cntrStudy', :frame => frame).selected_options(&:text)
提供所选选项中的文本数组:
[“SLC”]

尝试将您的rspec更改为:

expect(page.cell_element(:xpath => "//td[.='Lorem Ipsum']/following-sibling::td[1]", :frame => frame).text).to be == @sltedStudy.first
或者这个:

expect([page.cell_element(:xpath => "//td[.='Lorem Ipsum']/following-sibling::td[1]", :frame => frame).text]).to be == @sltedStudy

看起来是这样的:

@sltedStudy = page.select_list_element(:id => 'cntrStudy', :frame => frame).selected_options(&:text)
提供所选选项中的文本数组:
[“SLC”]

尝试将您的rspec更改为:

expect(page.cell_element(:xpath => "//td[.='Lorem Ipsum']/following-sibling::td[1]", :frame => frame).text).to be == @sltedStudy.first
或者这个:

expect([page.cell_element(:xpath => "//td[.='Lorem Ipsum']/following-sibling::td[1]", :frame => frame).text]).to be == @sltedStudy

看起来是这样的:

@sltedStudy = page.select_list_element(:id => 'cntrStudy', :frame => frame).selected_options(&:text)
提供所选选项中的文本数组:
[“SLC”]

尝试将您的rspec更改为:

expect(page.cell_element(:xpath => "//td[.='Lorem Ipsum']/following-sibling::td[1]", :frame => frame).text).to be == @sltedStudy.first
或者这个:

expect([page.cell_element(:xpath => "//td[.='Lorem Ipsum']/following-sibling::td[1]", :frame => frame).text]).to be == @sltedStudy

selected\u options
方法返回
Option
对象的
Array
。调用
(&:text)
与调用:

selected_options.collect { |opt| opt.text }
这将返回一个包含文本的新数组。所以
@sltedStudy
是一个数组。当您将其与调用
cell\u元素
中的文本进行比较时,它只是返回一个
字符串
。在匹配器中,您正在将
数组
字符串
进行比较。您可以更改为使用
include
matcher,也可以简单地将数组的第一个元素看作Surya


另一方面,我认为您所采取的方法实际上违背了使用页面对象的全部目的。在当前的调用中,您似乎在页面对象之外公开了实现细节。我强烈建议封装元素类型以及页面内部路径的知识。

选择的
选项
方法返回
选项
对象的
数组。调用
(&:text)
与调用:

selected_options.collect { |opt| opt.text }
这将返回一个包含文本的新数组。所以
@sltedStudy
是一个数组。当您将其与调用
cell\u元素
中的文本进行比较时,它只是返回一个
字符串
。在匹配器中,您正在将
数组
字符串
进行比较。您可以更改为使用
include
matcher,也可以简单地将数组的第一个元素看作Surya


另一方面,我认为您所采取的方法实际上违背了使用页面对象的全部目的。在当前的调用中,您似乎在页面对象之外公开了实现细节。我强烈建议封装元素类型以及页面内部路径的知识。

选择的
选项
方法返回
选项
对象的
数组。调用
(&:text)
与调用:

selected_options.collect { |opt| opt.text }
这将返回一个包含文本的新数组。所以
@sltedStudy
是一个数组。当您将其与调用
cell\u元素
中的文本进行比较时,它只是返回一个
字符串
。在匹配器中,您正在将
数组
字符串
进行比较。您可以更改为使用
include
matcher,也可以简单地将数组的第一个元素看作Surya


另一方面,我认为您所采取的方法实际上违背了使用页面对象的全部目的。在当前的调用中,您似乎在页面对象之外公开了实现细节。我强烈建议封装元素类型以及页面内部路径的知识。

选择的
选项
方法返回
选项
对象的
数组。调用
(&:text)
与调用:

selected_options.collect { |opt| opt.text }
这将返回一个包含文本的新数组。所以
@sltedStudy
是一个数组。当您将其与调用
cell\u元素
中的文本进行比较时,它只是返回一个
字符串
。在匹配器中,您正在将
数组
字符串
进行比较。您可以更改为使用
include
matcher,也可以简单地将数组的第一个元素看作Surya

另一方面,我认为您所采取的方法实际上违背了使用页面对象的全部目的。在当前的调用中,您似乎在页面对象之外公开了实现细节。我强烈建议封装元素类型以及页面内部路径的知识。

尝试使用以下方法: 当前的\u月\u元素。选择的\u选项[0]。text

尝试如下使用: 当前的\u月\u元素。选择的\u选项[0]。text

尝试如下使用: 当前的\u月\u元素。选择的\u选项[0]。text

尝试如下使用:
当前\u月\u元素。已选择\u选项[0]。文本数组,当然是。我忘了selected_options会返回一个所选选项的数组:)谢谢。这个答案可能对OP有效,但我强烈建议不要使用这个答案,因为Cheezy指出了下面的原因。数组,是的,当然。我忘了selected_options会返回一个所选选项的数组:)谢谢。这个答案可能对OP有效,但我强烈建议不要使用这个答案,因为Cheezy指出了下面的原因。数组,是的,当然。我忘了selected_options会返回一个所选选项的数组:)谢谢。这个答案可能对OP有效,但我强烈建议不要使用这个答案,因为Cheezy指出了下面的原因。数组,是的,当然。我忘了selected_options会返回一个所选选项的数组:)谢谢。这个答案可能对OP有效,但我强烈建议不要使用这个答案,原因是C