这是我第一次在该论坛上发帖,我正在做一些硒webdriver测试,我从html UI收集了一些数据,并将其放入数组中:
consents = $driver.find_elements(:xpath,"//*[@id='main-display']/div[2]/div[2]/div/table/tbody/tr/td[7]//i")
,然后我用map处理了数组:
consent_values = consents.map { |consent| consent.attribute('class')}
打印我得到的数组:
["fa fa-check-circle", "fa fa-circle-thin", "fa fa-check-circle", "fa fa-circle-thin", "fa fa-circle-thin", "fa fa-check-circle", "fa fa-circle-thin", "fa fa-circle-thin", "fa fa-check-circle,....]
1)有没有办法在地图上删除数组中所有字符串中的“ fa”?
2)怎样将字符串“ fa fa-check-circle”更改为true,并将“ fa fa-circle-thin”更改为false,这样我会得到:[true,false,true,....]
谢谢,
基本上2)消除了1)的必要性,因此您可以进行以下操作:
consent_values = consents.map do |consent|
case consent.attribute('class')
when "fa fa-check-circle" then true
when "fa fa-circle-thin" then false
else nil
end
end
要从"fa "
字符串中删除前缀,可以使用String#[]
:
"fa fa-check-circle"[/(?<=\Afa ).*/]
#⇒ "fa-check-circle"
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句