我需要在monthpicker中選擇月份。 的XPath具有隨機數如何點擊在xpath或css路徑中有隨機數的元素?
//*[@id="monthpicker_037945738616321245"]/table/tbody/tr[4]/td[3]
CSS路徑具有隨機數過多
#monthpicker_037945738616321245 > table > tbody > tr:nth-child(4) > td:nth-child(3)
另外3頁蛾採摘,但只有一個是可見的。 包含此monthpicker的每個div都具有包含隨機數的id。 monthpicker_04289214732160275
或monthpicker_04395144395656033
<table class="mtz-monthpicker">
<tbody class="mtz-monthpicker">
<tr class="mtz-monthpicker">
<td class="ui-state-default mtz-monthpicker mtz-monthpicker-month" style="padding:5px;cursor:default;" data-month="1">Январь</td>
<td class="ui-state-default mtz-monthpicker mtz-monthpicker-month" style="padding:5px;cursor:default;" data-month="2">Февраль</td>
<td class="ui-state-default mtz-monthpicker mtz-monthpicker-month" style="padding:5px;cursor:default;" data-month="3">Март</td>
</tr>
<tr class="mtz-monthpicker">
<td class="ui-state-default mtz-monthpicker mtz-monthpicker-month" style="padding:5px;cursor:default;" data-month="4">Апрель</td>
<td class="ui-state-default mtz-monthpicker mtz-monthpicker-month" style="padding:5px;cursor:default;" data-month="5">Май</td>
<td class="ui-state-default mtz-monthpicker mtz-monthpicker-month" style="padding:5px;cursor:default;" data-month="6">Июнь</td>
</tr>
<tr class="mtz-monthpicker">
<td class="ui-state-default mtz-monthpicker mtz-monthpicker-month" style="padding:5px;cursor:default;" data-month="7">Июль</td>
<td class="ui-state-default mtz-monthpicker mtz-monthpicker-month" style="padding:5px;cursor:default;" data-month="8">Август</td>
<td class="ui-state-default mtz-monthpicker mtz-monthpicker-month" style="padding:5px;cursor:default;" data-month="9">Сентябрь</td>
</tr>
<tr class="mtz-monthpicker">
<td class="ui-state-default mtz-monthpicker mtz-monthpicker-month" style="padding:5px;cursor:default;" data-month="10">Октябрь</td>
<td class="ui-state-default mtz-monthpicker mtz-monthpicker-month" style="padding:5px;cursor:default;" data-month="11">Ноябрь</td>
<td class="ui-state-default mtz-monthpicker mtz-monthpicker-month" style="padding:5px;cursor:default;" data-month="12">Декабрь</td>
</tr>
</tbody>
</table>
我試圖
@b.table(:class => 'mtz-monthpicker').tr(:class => 'mtz-monthpicker').td(:class => 'ui-state-default mtz-monthpicker mtz-monthpicker-month').click
CSS路徑:#monthpicker_020622412423150185 > table > tbody > tr:nth-child(4) > td:nth-child(3)
的xpath://*[@id="monthpicker_020622412423150185"]/table/tbody/tr[4]/td[3]
另外angular.is用於該前端。
如何在本月採購員中選擇並點擊一個月?
我使用watir-webdrievr。我試過:@ b.td(:xpath,「// * [contains(@id,'monthpicker _')]/table/tbody/tr [4]/td [3]」)。when_present.click @b。 td(:xpath,「// * [starts-with(@id,'monthpicker _')]/table/tbody/tr [4]/td [3]」)。when_present.click @ b.td(:xpath ,「//*[.='Март']").when_present.click但是我在90秒後才超時,等待{:xpath => .... – user1371940
之後發生了什麼? – Saifur
這個xpath可以工作,但是這個元素目前不可見,硒不能與它交互。此外這個元素沒有任何可以隱藏的樣式。但它有父親溢出:隱藏的風格。我嘗試用javascript代碼更改父元素的可見性:monthPikerOverflow = @ b.div(:xpath,「// * [contains(@id,'monthpicker_')]」) script = << - JS arguments [0] .style.overflow ='visible'; arguments [0] .style.visibility ='visible'; JS @ b.execute_script(script,monthPikerOverflow),但它沒有幫助。所以我一直在尋找解決方案。 – user1371940