Selenium:如何使用FindElementByXPath来识别元素
我需要单击导出器。
这是html代码,
<div class="ui-dialog-buttonset">
<button type="button" title="" style="" class="call-to-action ui-button ui-corner-all ui-widget button-default">Exportar</button>
<button type="button" title="" class="ui-button ui-corner-all ui-widget button-cancel">Cancelar</button>
</div>
<div tabindex="-1" role="dialog" style="height: auto; width: 440px; top: 211.656px; left: 460px; z-index: 101;" class="ui-dialog ui-widget ui-widget-content ui-front ui-dialog-buttons ui-draggable ui-dialog-newest" aria-describedby="popup-exportar-relatorio" aria-labelledby="ui-id-2"><div class="ui-dialog-titlebar ui-corner-all ui-widget-header ui-helper-clearfix ui-draggable-handle"><span id="ui-id-2" class="ui-dialog-title">Exportar relatório</span><button type="button" class="ui-button ui-corner-all ui-widget ui-button-icon-only ui-dialog-titlebar-close" title=""><span class="ui-button-icon ui-icon ui-icon-closethick"></span><span class="ui-button-icon-space"> </span></button></div><div id="popup-exportar-relatorio" style="text-align: left; width: auto; min-height: 0px; max-height: none; height: auto;" class="ui-dialog-content ui-widget-content">
<div class="col-xs-12 group-item-form">
<label for="formato" class="label-item-form">Formato de arquivo</label>
<select id="formato" name="formato" class="wh100 bling-item-form">
<option selected="" value="csv">CSV</option>
<option value="pdf">PDF</option>
<option value="xls">XLS</option>
</select>
</div>
<div id="div-orientacao-pagina" class="col-xs-12 group-item-form" style="display: none;">
<span class="linha_form wh100 margin_top12"></span>
<label for="orientacao-pagina-select" class="label-item-form">Orientação da página</label>
<select id="orientacao-pagina-select" name="orientacao-pagina-select" class="wh100 bling-item-form">
<option selected="" value="retrato">Retrato</option>
<option value="paisagem">Paisagem</option>
</select>
</div>
<div id="div-exportar-relatorio-opcoes" class="col-xs-12 group-item-form" style="display: none;">
<span class="linha_form wh100 margin_top12"></span>
<label for="orientacao-pagina-select" class="label-item-form">Orientação da página</label>
<select id="orientacao-pagina-select" name="orientacao-pagina-select" class="wh100 bling-item-form">
<option selected="" value="retrato">Retrato</option>
<option value="paisagem">Paisagem</option>
</select>
</div>
<div id="options-container">
<div id="div_exportar_cabecalho" class="col-xs-12 group-item-form" style="display: none;">
<span class="linha_form wh100 margin_top12"></span>
<div class="vertical-align-inline"><div class="input-checkbox">
<input type="checkbox" id="opc_exportar_cabecalho" name="opc-exportar-cabecalho" data-option="cabecalho" checked="">
<label for="opc_exportar_cabecalho"></label></div><label for="opc_exportar_cabecalho" class="label-item-form-input">Exportar com logo da empresa</label></div>
</div>
<h5 class="subtitulo-popup margin_top10" style="padding: 5px">Opções</h5>
<div class="form-item wh100">
<div class="vertical-align-inline"><div class="input-checkbox">
<input type="checkbox" id="opc-exportar-totalizador" name="opc-exportar-totalizador" data-option="totalizador">
<label for="opc-exportar-totalizador"></label></div><label for="opc-exportar-totalizador" class="label-item-form-input">
Exportar com totalizadores
</label></div>
</div>
<br>
</div>
<div class="col-xs-12 group-item-form">
<div id="xls-cell-limit-info" class="alert-mini-box alert-mini-box-info alert-mini-box-transparent" style="display: none;">
<p>
O formato <strong>XLS</strong> possui limite de <strong>trinta mil caracteres</strong> por célula de acordo com sua especificação.<br>
Recomenda-se o uso do formato <strong>CSV</strong> para exportação de dados que excedam este limite.
</p>
</div>
</div>
</div><div class="ui-dialog-buttonpane ui-widget-content ui-helper-clearfix"><div class="ui-dialog-buttonset"><button type="button" title="" style="" class="call-to-action ui-button ui-corner-all ui-widget button-default">Exportar</button><button type="button" title="" class="ui-button ui-corner-all ui-widget button-cancel">Cancelar</button></div></div></div>
谢谢您的帮助。这只是代码的一小部分。 谢谢你的帮助。这只是代码的一小部分。 谢谢你的帮助。这只是代码的一小部分。 谢谢你的帮助。这只是代码的一小部分。 谢谢你的帮助。这只是代码的一小部分。 谢谢你的帮助。这只是代码的一小部分。 谢谢你的帮助。这只是代码的一小部分。
I need to click on Exportar.
This is the html code
<div class="ui-dialog-buttonset">
<button type="button" title="" style="" class="call-to-action ui-button ui-corner-all ui-widget button-default">Exportar</button>
<button type="button" title="" class="ui-button ui-corner-all ui-widget button-cancel">Cancelar</button>
</div>
<div tabindex="-1" role="dialog" style="height: auto; width: 440px; top: 211.656px; left: 460px; z-index: 101;" class="ui-dialog ui-widget ui-widget-content ui-front ui-dialog-buttons ui-draggable ui-dialog-newest" aria-describedby="popup-exportar-relatorio" aria-labelledby="ui-id-2"><div class="ui-dialog-titlebar ui-corner-all ui-widget-header ui-helper-clearfix ui-draggable-handle"><span id="ui-id-2" class="ui-dialog-title">Exportar relatório</span><button type="button" class="ui-button ui-corner-all ui-widget ui-button-icon-only ui-dialog-titlebar-close" title=""><span class="ui-button-icon ui-icon ui-icon-closethick"></span><span class="ui-button-icon-space"> </span></button></div><div id="popup-exportar-relatorio" style="text-align: left; width: auto; min-height: 0px; max-height: none; height: auto;" class="ui-dialog-content ui-widget-content">
<div class="col-xs-12 group-item-form">
<label for="formato" class="label-item-form">Formato de arquivo</label>
<select id="formato" name="formato" class="wh100 bling-item-form">
<option selected="" value="csv">CSV</option>
<option value="pdf">PDF</option>
<option value="xls">XLS</option>
</select>
</div>
<div id="div-orientacao-pagina" class="col-xs-12 group-item-form" style="display: none;">
<span class="linha_form wh100 margin_top12"></span>
<label for="orientacao-pagina-select" class="label-item-form">Orientação da página</label>
<select id="orientacao-pagina-select" name="orientacao-pagina-select" class="wh100 bling-item-form">
<option selected="" value="retrato">Retrato</option>
<option value="paisagem">Paisagem</option>
</select>
</div>
<div id="div-exportar-relatorio-opcoes" class="col-xs-12 group-item-form" style="display: none;">
<span class="linha_form wh100 margin_top12"></span>
<label for="orientacao-pagina-select" class="label-item-form">Orientação da página</label>
<select id="orientacao-pagina-select" name="orientacao-pagina-select" class="wh100 bling-item-form">
<option selected="" value="retrato">Retrato</option>
<option value="paisagem">Paisagem</option>
</select>
</div>
<div id="options-container">
<div id="div_exportar_cabecalho" class="col-xs-12 group-item-form" style="display: none;">
<span class="linha_form wh100 margin_top12"></span>
<div class="vertical-align-inline"><div class="input-checkbox">
<input type="checkbox" id="opc_exportar_cabecalho" name="opc-exportar-cabecalho" data-option="cabecalho" checked="">
<label for="opc_exportar_cabecalho"></label></div><label for="opc_exportar_cabecalho" class="label-item-form-input">Exportar com logo da empresa</label></div>
</div>
<h5 class="subtitulo-popup margin_top10" style="padding: 5px">Opções</h5>
<div class="form-item wh100">
<div class="vertical-align-inline"><div class="input-checkbox">
<input type="checkbox" id="opc-exportar-totalizador" name="opc-exportar-totalizador" data-option="totalizador">
<label for="opc-exportar-totalizador"></label></div><label for="opc-exportar-totalizador" class="label-item-form-input">
Exportar com totalizadores
</label></div>
</div>
<br>
</div>
<div class="col-xs-12 group-item-form">
<div id="xls-cell-limit-info" class="alert-mini-box alert-mini-box-info alert-mini-box-transparent" style="display: none;">
<p>
O formato <strong>XLS</strong> possui limite de <strong>trinta mil caracteres</strong> por célula de acordo com sua especificação.<br>
Recomenda-se o uso do formato <strong>CSV</strong> para exportação de dados que excedam este limite.
</p>
</div>
</div>
</div><div class="ui-dialog-buttonpane ui-widget-content ui-helper-clearfix"><div class="ui-dialog-buttonset"><button type="button" title="" style="" class="call-to-action ui-button ui-corner-all ui-widget button-default">Exportar</button><button type="button" title="" class="ui-button ui-corner-all ui-widget button-cancel">Cancelar</button></div></div></div>
Thank you for the help. This is just a small part of the code.
Thank you for the help. This is just a small part of the code.
Thank you for the help. This is just a small part of the code.
Thank you for the help. This is just a small part of the code.
Thank you for the help. This is just a small part of the code.
Thank you for the help. This is just a small part of the code.
Thank you for the help. This is just a small part of the code.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要定位文本为 Exportar 的元素,您可以使用以下任一定位器策略:
xpath:
To locate the element with text as Exportar you can use either of the following locator strategies:
css_selector:
xpath:
试试这个:
Try this :