0

セレンを使用してUI要素を見つけようとしていますが、Xpathは動的にevrytimeを変更していますここにソースがあります

<div id="tab-1080" class="x-tab x-box-item x-tab-default x-top x-tab-top x-tab-default-     top x-noicon x-tab-noicon x-tab-default-noicon x-active x-tab-active x-tab-default-active x-top-active x-tab-top-active x-tab-default-top-active" style="margin: 0px; left: 406px; top: 0px;">
<em id="tab-1080-btnWrap" class="">
<button id="tab-1080-btnEl" class="x-tab-center" autocomplete="off" role="button"  hidefocus="true" type="button">
<span id="tab-1080-btnInnerEl" class="x-tab-inner" style="">Report Center</span>
<span id="tab-1080-btnIconEl" class="x-tab-icon x-hide-display"> </span>
</button>
</em>
</div>

これを一意に見つける必要がありますが、ID 1080はevreytimeを変更し続けますか?私のウェブページでこのボタンを区別する唯一の属性であるスパンID「レポートセンター」を使用して検索する方法を教えてもらえますか。

4

3 に答える 3

0

使用できます

//span[text()='Report Center']
于 2012-08-03T06:39:56.163 に答える
0

個人的には css を使用します。これらは xpath よりも高速であり、一般的にコミュニティによって優れていると認められています。また、いくつかの調査を行うことで、使いやすくなると思います。

http://sauceio.com/index.php/2010/01/selenium-totw-css-selectors-in-selenium-demystified/

span.x-tab-inner ==> finds the element by its class
span[id*=btnInnerEl]` ==> finds element by a partial piece (substring) of the id
于 2012-08-03T08:19:11.073 に答える