2016-11-29 93 views
1

任何人都可以告訴如何識別selenium webdriver中的以下元素。以下是html版吧:如何使用Selenium webdriver中的cssSelector來識別多個參數

<select ng-model="tripDetails.destinationId" ng-change="$parent.$parent.$parent.updateTripSourceCity($index)" required="" class="ng-touched ng-dirty ng-valid-parse ng-valid ng-valid-required"> 
+0

請更新您的編碼部分 –

+0

<選擇NG-模型= 「tripDetails.destinationId」 NG-變化= 「$父。$父。$父。$ parent.updateTripSourceCity($指數)」需要=「」class =「ng-touch ng-dirty ng-valid-parse ng-valid ng-valid-required」>

+0

@SaEChowdary這是它的html版本 –

回答

1

嘗試通過類名與以下CSS選擇

select.ng-touched.ng-dirty.ng-valid-parse.ng-valid.ng-valid-required 
1

我猜這個班不是唯一的識別它,那麼它很可能是最好通過ng-model進行選擇。試試這個作爲CSS選擇器:

'select[ng-model="tripDetails.destinationId"]' 
+0

它沒有工作拋出錯誤,找不到元素。 –

0

在你的情況下,最好使用xpath搜索特定的元素。首先使用上面提到的元素層次結構中上面的xpath搜索任何父元素,然後從該父元素中搜索元素。嘗試這樣的事情

//parent-xpath/child-xpath(mentioned element) 
//div[@id='element-id']/select[@ng-model='tripDetails.destinationId'] 
+0

'CSS' selector does not work in this way'// parent-css/child-css' ...它看起來像'XPath'。 CSS選擇器應該是'parent-css child-css'。而且,OP說過'select [ng-model =「tripDetails.destinationId」]'沒有被找到。顯然,'div [id ='element-id'] select [ng-model ='tripDetails.destinationId']'應該返回相同的結果 – Andersson

+0

@Andersson我編輯了我的答案 –

相關問題