2016-02-02 90 views
-2

如何找到Selenium下面的元素?如何使用Xpath定位此元素?

<input id="mainForm:field_LayFact450505264_16032015_145612--Order-ServiceClass_R" class="iceSelInpTxtTxt fieldTxt" type="text" value="" style="width: 150px;" onmousedown="this.focus();" onfocus="setFocus(this.id);svOnFocus(formOf(this), this, event, false);" onblur="setFocus('');svOnBlur(formOf(this), this, event);" name="mainForm:field_LayFact450505264_16032015_145612--Order-ServiceClass_R" autocomplete="off"> 

我試着用ends-with,它沒有工作。

+0

哪裏是你的數據,HTML代碼和XPath你已經試過這件..? –

+0

ananya

+0

如果ID不是唯一的,每次您可以嘗試類名稱。您可以通過類名搜索元素,或者如果您想使用xpath嘗試此操作//輸入[@ class =「iceSelInpTxtTxt fieldTxt」] – Nitesh

回答

0
WebElement Element = driver.findElement(By.xpath("Try any Below xpaths")) 

如果輸入ID是唯一的,然後使用下面的XPath

//input[@id='mainForm:field_LayFact450505264_16032015_145612--Order-ServiceClass_R'] 

OR

//input[@name='mainForm:field_LayFact450505264_16032015_145612--Order-ServiceClass_R'] 

,或者如果兩個編號和名稱的組合使其唯一然後用下面的XPath

//input[@name='mainForm:field_LayFact450505264_16032015_145612--Order-ServiceClass_R' and @id='mainForm:field_LayFact450505264_16032015_145612--Order-ServiceClass_R'] 

OR

//input[@class='iceSelInpTxtTxt fieldTxt'] 

希望它會幫助你:)

0

您可以使用以下

WebElement inputClass = driver.findElement(By.className("iceSelInpTxtTxt fieldTxt"));