Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/37.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/22.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
Html 访问在Ruby with Selenium中选中复选框时显示的类属性_Html_Css_Ruby_Xpath_Selenium - Fatal编程技术网

Html 访问在Ruby with Selenium中选中复选框时显示的类属性

Html 访问在Ruby with Selenium中选中复选框时显示的类属性,html,css,ruby,xpath,selenium,Html,Css,Ruby,Xpath,Selenium,我有一个如下所示的标签: <ul id="genres-bar" > 如果不检查,它就会消失 我对html、css、XPath等都是新手,我可能很难找到类似的问题,但到目前为止,我的研究还没有给我一个我能理解的答案 这个答案很有帮助,但是是用java编写的。我不知道如何将它应用到我的问题中,但它似乎非常相似: 这是我到目前为止定位元素的尝试: verify {@driver.find_element(:xpath, '//*[@id="genres-bar" @class=" r

我有一个如下所示的标签:

<ul id="genres-bar" >
如果不检查,它就会消失

我对html、css、XPath等都是新手,我可能很难找到类似的问题,但到目前为止,我的研究还没有给我一个我能理解的答案

这个答案很有帮助,但是是用java编写的。我不知道如何将它应用到我的问题中,但它似乎非常相似:

这是我到目前为止定位元素的尝试:

verify {@driver.find_element(:xpath, '//*[@id="genres-bar" @class=" romance"]')}

下面的两部分可能会对您有所帮助。虽然我不清楚您的需求:

而且会很有帮助。就你而言

@driver.find_element(:css, '#genres-bar').css_value('background-color')
# => '#FF0000'
@driver.find_element(:css, '#genres-bar').attribute('class')
# => " romance"

你这样做怎么样

verify {@driver.find_element(:xpath, '//*[@id="genres-bar"][@class=" romance"]')}


您几乎正确地使用了xpath。

要检查什么?如何验证/访问此属性?您想要访问的属性/当我选中复选框时:class=“roman”会出现,css片段也会出现。我想在我写这个问题时,我假设这些东西是相关的,通过访问class=“romance”我可以验证元素是否改变了颜色。检查我的答案,希望这会对你有所帮助。你的问题现在解决了吗?昨天晚上我不得不离开它,今天就跳到它上面,并且得到了正确的答案。非常感谢。
@driver.find_element(:css, '#genres-bar').css_value('background-color')
# => '#FF0000'
@driver.find_element(:css, '#genres-bar').attribute('class')
# => " romance"
verify {@driver.find_element(:xpath, '//*[@id="genres-bar"][@class=" romance"]')}
verify {@driver.find_element(:xpath, '//*[@id="genres-bar" and @class=" romance"]')}