Search code examples
rubycapybara

Is there another way to click on a menu item with Capybara


Friends try anyway but it is not being possible to click on the Gestão de Materiais Menu item. One situation I need is to scroll this menu to view and click on the item menu. But I'm not sure why he is clicking on the menu item below I tried using SitePrism and pure capybara but it is not possible. When it runs, it is clicking on Gestao de Empresas

capybara: find(:xpath, "//div[contains(text(),'Gestão de Materiais')]" ).click find(:xpath, '//*[@id="TBB_tbm2"]/div[3]/div[2]').click

site Prism: element :item_mn_gestao_materiais, :xpath, "//div[contains(text(),'Gestão de Materiais')]" element :item_mn_gestao_materais, :css, '#TBB_tbm2 img[src*=articoli64]' def cadastra_diametro_material_ativo item_mn_gestao_materiais.click end enter image description here Menu Principal Modulo Básico Gestão Instalações Gestão de Materiais <div

enter image description here


Solution

  • There is no point in trying Capybara and SitePrism, SitePrism uses capybara so if capybaras click doesn't work for you then SitePrism isn't going to either.

    Given the visible info, if I was writing this I'd write

    find('#TBB_tbm2 > div', text: 'Gestão de Materiais').click
    

    following the two rules

    1. Don't use XPath unless absolutely necessary
    2. Write the minimal selector necessary

    beyond that it's impossible to go any further with the current information