2016-11-29 92 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我编辑了我的答案 –

相关问题