我试图在页面中选择一个特定按钮,但守夜者似乎找不到它。如果我尝试按班级调用它,那么它可以工作,但是没有选择我想要它的按钮

<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>


如果我尝试选择<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>,则它不起作用,但是夜表将其识别为有效命令。

如果我尝试直接选择按钮,即<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>,它将无法识别我的命令。如果有错,请退还给我。

尝试使用.click('li[class="ui-menuitem ui-widget ui-corner-all"]')选择元素

如果有人可以帮助我解决这个问题,我将不胜感激。如果您需要有关代码的更多信息,请问我。

最佳答案

您应该使用ID进行选择。该ID被保证是唯一的。

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


假设页面已加载并且该元素不在iframe中,则没有理由上述点击不起作用。

07-27 14:39