繁体   English   中英

无法在Java中使用WebDriver单击按钮

[英]Not able to click a button using WebDriver in Java

填写一些文本字段后,我需要单击“保存”按钮。 问题是每次重新加载页面时xpath都会不断变化,id是动态的。 请帮我点击WebDriver中的这个按钮。 是否可以使用按钮的文本单击? 这是firebug输出。 在此输入图像描述

请帮助生成目标以单击此按钮。

</div>
<div class="x-window-bl">
<div class="x-window-br">
<div class="x-window-bc">
<div id="ext-gen427" class="x-window-footer">
<div class="x-panel-btns-ct" id="ext-gen503">
<div id="ext-gen496" class="x-panel-btns x-panel-btns-right">
<table cellspacing="0">
<tbody>
<tr>
<td id="ext-gen430" class="x-panel-btn-td dms_bluebtn dms_smallbtn">
<table id="ext-comp-1039" class="x-btn-wrap x-btn " cellspacing="0" cellpadding="0"     border="0" style="width: 75px;">
<tbody>
<tr>
<td class="x-btn-left" id="ext-gen537">
<i>&nbsp;</i>
</td>
<td id="ext-gen498" class="x-btn-center">
<em unselectable="on">
<button id="ext-gen432" class="x-btn-text" type="button">Save</button>
</em>
</td>
<td class="x-btn-right">
</tr>
</tbody>
</table>
</td>
<td id="ext-gen438" class="x-panel-btn-td dms_greybtn dms_smallbtn">
<table id="ext-comp-1040" class="x-btn-wrap x-btn " cellspacing="0" cellpadding="0"         border="0" style="width: 75px;">
<tbody>
<tr>
<td class="x-btn-left">
<i id="ext-gen562">&nbsp;</i>
</td>
<td id="ext-gen513" class="x-btn-center">
<em unselectable="on">
<button id="ext-gen440" class="x-btn-text" type="button">Cancel</button>
</em>
</td>
<td class="x-btn-right" id="ext-gen548">
<i>&nbsp;</i>

我会使用XPath。 假设您在此页面上只有一个按钮名称保存,您可以执行以下操作:

By.xpath("//button[text() = 'Save']")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM