【问题标题】:How to identify multiple parameters using cssSelector in Selenium webdriver如何在 Selenium webdriver 中使用 cssSelector 识别多个参数
【发布时间】:2017-04-13 11:49:50
【问题描述】:

谁能告诉如何识别selenium webdriver 中的以下元素。以下是它的html 版本:

<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">

【问题讨论】:

  • 请更新您的编码部分
  • @SaEChowdary 这是它的 html 版本
  • 之前你在问题中评论过它
  • 请阅读How to Ask。请提供您尝试过的代码和执行结果,包括任何错误消息等。同时提供指向页面和/或相关 HTML 的链接。

标签: javascript java angularjs selenium selenium-webdriver


【解决方案1】:

尝试使用以下CSS选择器通过类名来识别它

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

【讨论】:

    【解决方案2】:

    我猜这方面的课程不是唯一的,所以最好选择ng-model。试试这个作为 CSS 选择器:

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

    【讨论】:

    • 它没有工作,抛出找不到元素的错误。
    【解决方案3】:

    在您的情况下,最好使用 xpath 搜索该特定元素。首先使用上述元素层次结构中的 xpath 搜索任何父元素,然后从该父元素中搜索您的元素。试试这样的

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

    【讨论】:

    • CSS 选择器不能以这种方式工作 //parent-css/child-css... 看起来像 XPathCSS 选择器应为 parent-css child-css。此外,OP 说没有找到select[ng-model="tripDetails.destinationId"]。显然,div[id='element-id'] select[ng-model='tripDetails.destinationId'] 应该返回相同的结果
    猜你喜欢
    • 2016-11-11
    • 2011-12-14
    • 2018-10-14
    • 1970-01-01
    • 2017-07-13
    • 2017-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多