I have html like below and I want to get the element by "sku-code"(there is a hyphen in it)
<div class="leavemessagebox" style="position: relative;" sku-code="m_showcase">
when I used
browser.div(:sku-code=>'m_showcase')
ruby reported an error
ERROR:undefined local variable or method `code' for #<AUT::WebClient:0x2c59650>
It sames ruby can't recognize "sku-code" as a name, anyone can give me any suggestion about how to get the element by "sku-code"? thanks. Sorry for not explain myself clearly. there are many elements that have sku-code selector and I want to collect them all in a list, so the class name and tag name isn't stable. how can i do that
:sku-code
is not a valid symbol literal. It is however valid Ruby code, it is parsed as:So, you are trying to call a method named
code
and subtracting its return value from the symbol:sku
, which obviously doesn't make sense.But you can quote the symbol literal, of course:
Looks like Watir WebDriver. Try use css (preferred) or xpath.
Documention on CSS's attribute selector is here.
So basically the above selector finds all elements with attribute
sku-code
equals tom_showcase
.browser.element(:css => ".leavemessagebox[sku-code='m_showcase']") I think this will still the specific CSS.
Please Let me know is the above CSS is working or Not.