I’m checking results of values to verify that they are correct.
Using watir-webdriver.
In this case javascript generates a color class:
eg:
<span class="storyEdit limeGreen"> x </span>
in ruby currently I’m trying to parse the information from the using .html
so this is something like what I’ve parse so far
=> <span class=\"storyEdit limeGreen\"> x </span>
I’d like to only return limeGreen so I can say:
color = resultOfParsedSpan
This would be for a few different colours, so I was wondering is there a way to only pull the class name from the html?
If I haven’t explained anything well enough, please feel free to let me know so I can add extra information!
Watir let’s you do this directly; you do not need to manually parse the HTML yourself. The
Element#class_namemethod will give you the element’s class.Example (assuming it is the first span):
From that, you would have to parse the string to figure out what color it is. Given that the classes might be in any order and the infinite number of possible colors, I do not believe there is a general way to get just the color. The solution would depend on what you want to do with
colorand if the possible colors are known ahead of time.