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