1

Im trying to select an specific button in my page, but nightwatch can't seem to find it. If I try to call it by class, it works but doesn't select the button that I want it to

<div id="btGerar_documentosLote_menu" class="ui-menu ui-menu-dynamic ui-widget ui-widget-content ui-corner-all ui-helper-clearfix ui-shadow" role="menu">
<ul class="ui-menu-list ui-helper-reset"><li class="ui-menuitem ui-widget ui-corner-all" role="menuitem">
enter code here
<a tabindex="-1" id="lote-form-button-gerar-xml-tiss" class="ui-menuitem-link ui-corner-all" href="#" onclick="PrimeFaces.ab({s:&quot;lote-form-button-gerar-xml-tiss&quot;,u:&quot;lote-form-panel-grid-dados-lote lote-form-buttons&quot;,onst:function(cfg){PF('statusDialog').show();;},onco:function(xhr,status,args){PF('statusDialog').hide();;},f:&quot;form&quot;});return false;">
<span class="ui-menuitem-text">Gerar XML TISS</span
></a></li>
<li class="ui-menuitem ui-widget ui-corner-all" role="menuitem"><a tabindex="-1" id="lote-form-button-gerar-impressao-tiss" class="ui-menuitem-link ui-corner-all" href="#" onclick="PrimeFaces.ab({s:&quot;lote-form-button-gerar-impressao-tiss&quot;,u:&quot;form&quot;,onst:function(cfg){PF('statusDialog').show();;},onco:function(xhr,status,args){PF('statusDialog').hide();;},f:&quot;form&quot;});return false;"><span class="ui-menuitem-text">Gerar Impressão TISS</span></a>
</li>
<li class="ui-menuitem ui-widget ui-corner-all" role="menuitem">
<a tabindex="-1" id="lote-form-button-gerar-documentos-lote" class="ui-menuitem-link ui-corner-all" href="#" onclick="PrimeFaces.ab({s:&quot;lote-form-button-gerar-documentos-lote&quot;,u:&quot;form&quot;,onst:function(cfg){PF('statusDialog').show();;},onco:function(xhr,status,args){PF('statusDialog').hide();;},f:&quot;form&quot;});return false;">
<span class="ui-menuitem-text">Gerar Documentos Lote</span></a></li></ul></div>

If I try to select <li class="ui-menuitem ui-widget ui-corner-all" role="menuitem"><a tabindex="-1" id="lote-form-button-gerar-xml-tiss" class="ui-menuitem-link ui-corner-all" href="#" onclick="PrimeFaces.ab({s:&quot;lote-form-button-gerar-xml-tiss&quot;,u:&quot;lote-form-panel-grid-dados-lote lote-form-buttons&quot;,onst:function(cfg){PF('statusDialog').show();;},onco:function(xhr,status,args){PF('statusDialog').hide();;},f:&quot;form&quot;});return false;"><span class="ui-menuitem-text">Gerar XML TISS</span></a></li>, it doesn't work but nightwatch recognizes it as a valid command.

If I try to select the button directly, which is <a tabindex="-1" id="lote-form-button-gerar-xml-tiss" class="ui-menuitem-link ui-corner-all" href="#" onclick="PrimeFaces.ab({s:&quot;lote-form-button-gerar-xml-tiss&quot;,u:&quot;lote-form-panel-grid-dados-lote lote-form-buttons&quot;,onst:function(cfg){PF('statusDialog').show();;},onco:function(xhr,status,args){PF('statusDialog').hide();;},f:&quot;form&quot;});return false;"><span class="ui-menuitem-text">Gerar XML TISS</span></a>, it doesn't recognize my command. Returns it to me as if it is wrong.

Trying to select the element by using .click('li[class="ui-menuitem ui-widget ui-corner-all"]')

If someone could help me solve this, i'd be grateful. If you want any more info on the code, just ask me for it.

disconnectedLynx
  • 101
  • 1
  • 11

1 Answers1

1

You should use the ID to select it. The ID is guaranteed to be unique.

.click("#lote-form-button-gerar-xml-tiss")

Assuming the page has loaded and this element is not in an iframe, there is no reason the above click shouldn't work.

QualiT
  • 1,934
  • 2
  • 18
  • 37
  • Thanks for the help. It actually worked. I have another question, I don't know if I can just ask it here, but I will. Does that same method apply to selecting checkboxes? I mean, checkboxes only have classes, not IDs. – disconnectedLynx Oct 09 '19 at 13:47
  • The proper etiquette here on stackoverflow is to upvote my answer if it solved the problem...if you add another using the blue Ask Question button, I'll see it. But I'd want to see the HTML that you're trying to select. – QualiT Oct 09 '19 at 16:37
  • 1
    I upvoted you, but Stack said that i don't have enough rep to actually show the upvote for other users. – disconnectedLynx Oct 09 '19 at 17:42