I am trying to click a link that is within a list of ordered items.
The list is a order of most watched videos.
I'm just trying to select the first list item, so that the broswer will navigate to the href.
Right now, i have
$website.element(:class => "gs-c-promo-heading nw-o-link gs-o-bullet__text gs-o-faux-block-link__overlay-link gel-pica-bold gs-u-pl@xs").click
I was not able to reproduce your exception. However, given the exception, the answer would be to remove the compound class name - ie you cannot have any spaces in the class locator.
Most of the classes seem generic, so could likely be removed. You could try:
$website.element(:class => "gs-c-promo-heading").click
If the classes really are important, you can use Watir's new multi-class locator. This builds a large XPath, which would not trigger Selenium's compound class checker.
$website.element(:class => ["gs-c-promo-heading", "nw-o-link", "gs-o-bullet__text", "gs-o-faux-block-link__overlay-link", "gel-pica-bold", "gs-u-pl@xs"]).click
To grab all of the items, I would locate the
li elements based on their
data-entityid attribute which looks descriptive:
$website.lis(data_entityid: /most-popular-watched/).each do |li| puts li.link.text end
This might also be a more descriptive way to click the first link: