<div id="div_12_1_1_1_3_1_2_1_1_1_2" class="Quantity CoachView CoachView_show" data-eventid="" data-viewid="qty" data-config="config12" data-bindingtype="Decimal" data-binding="local.priceBreak.quantity" data-type="com.ibm.bpm.coach.Snapshot_a30ea40f_cb24_4729_a02e_25dc8e12dcab.Quantity">
<div class="w-decimal w-group clearfix">
<div class="p-label-container span4">
<div class="p-fields-container controls-row span8 l-input fixed-units">
<input id="div_12_1_1_1_3_1_2_1_1_1_2-in" class="p-field span8" type="text" maxlength="16">
<input id="div_12_1_1_1_3_1_2_1_1_1_2-iu" class="p-unit span4" type="text" maxlength="2" style="display: none;">
<select class="p-unit span4" style="display: none;"></select>
<div class="p-unit span4">CM</div>
<div class="p-help-block"></div>
</div>
<div class="p-fields-container span8 l-output" style="display: none;">
</div>
</div>
<div id="div_12_1_1_1_3_1_2_1_1_1_3" class="Quantity CoachView CoachView_show" data-eventid="" data-viewid="Quantity2" data-config="config73" data-bindingtype="Integer" data-binding="local.priceBreak.numberDeliveries" data-type="com.ibm.bpm.coach.Snapshot_a30ea40f_cb24_4729_a02e_25dc8e12dcab.Quantity">
這裏怎麼點擊其ID的文本框「div_12_1_1_1_3_1_2_1_1_1_2式」 但對於一些情況的變化,以「div_5_1_1_1_3_1_2_1_1_1_2-在「如何點擊文本字段「數量」的ID值在不同的情況下改變
我曾嘗試用下面,
driver.findElement(By.xpath("//div/input[ends-with(@id,'__1_1_1_3_1_2_1_1_1_2-in')]")).sendKeys("98989998989");
,但它不工作..
輸出:
org.openqa.selenium.InvalidSelectorException:給定的選擇器// div/input [ends-with(@id,'__ 1_1_1_3_1_2_1_1_1_2-in')]無效或不導致WebElement。發生以下錯誤: InvalidSelectorError:由於以下錯誤,無法找到xpath表達式// div/input [ends-with(@id,'__ 1_1_1_3_1_2_1_1_1_2-in')]中的元素: [Exception ...「這個表達不是一個合法的表達。「代碼:「51」nsresult:「0x805b0033(NS_ERROR_DOM_INVALID_EXPRESSION_ERR)」location:「file:/// C:/Users/SUNIL~1.WAL/AppData/Local/Temp/anonymous4157273428687139624webdriver-profile/extensions/[email protected]/組件/ driver_component.js行:5956「] 命令持續時間或超時:41毫秒 有關此錯誤的文檔,請訪問:http://seleniumhq.org/exceptions/invalid_selector_exception.html 構建信息:版本:'2.37.0',修訂:'a7c61cb',時間:'二○一三年十月一十八日17時15分02' 秒
您在xpath表達式中測試的字符串的開頭有兩個下劃線,而HTML僅顯示單數下劃線。 – t0mppa