2017-08-10 64 views
0

我创建使用selenium-webdriver自动化测试与Ruby如何使用Ruby检查Selenium中是否包含某些元素?

所以我需要检查,如果我选择的元素中含有一种类单击后。 但我无法找到如何在Ruby的方式。

这是我的规格文件 -

it 'Desktop Cart open When click Bag icon' do 
    desktop_open_cart_button = @driver.find_element(:css, '.profile-container .bag-container .icon-bag') 
    sleep 2 
    desktop_open_cart_button.click 

    cartlist_container = @driver.find_element(:css, '.cartlist-container') 
    expect(cartlist_container.has_class?('active')).to be_truthy 
    sleep 2 
    end 

看起来我们没有has_class?方法。 那么如何检查点击后我的element是否包含类?

谢谢〜

回答

0

你可以得到的类属性,检查它是否具有预期的类

class_attribute = cartlist_container.attribute("class") 
expect(class_attribute.include?('active')).to be_truthy 
相关问题