【问题标题】:Have trouble with a CSS selectorCSS 选择器有问题
【发布时间】:2018-06-20 01:35:25
【问题描述】:

我似乎无法为此选择正确的 css 选择器:

<p ng-bind-html="hotelItem.details.allDetails.policyCancellationInstructions" class="ng-binding">
<div>To cancel this reservation <a href="https://www.getaroom.com/reservations?signature=57c685104ad3fe1525f17d0f54f2bde23ec82596&amp;utm_campaign=Affiliate&amp;utm_medium=cpa&amp;utm_source=studentuniverse.com">click here</a>. If you have questions regarding your booking contact Getaroom's customer care team: United States Customers: <a href="tel:+18002603895">800-260-3895</a>; United Kingdom Customers: <a href="tel:+08000124507">0800-012-4507</a></div> 
</p>

我试过没有用:

'span[ng-bind-html="hotelItem.details.allDetails.policyCancellationInstructions"] > div'

任何帮助表示赞赏!

【问题讨论】:

  • 提供的 HTML 示例适用于 p 节点(没有子节点,没有结束标记),而 CSS 选择器适用于 span。分享准确的 HTML
  • 您编写的 css 选择器包含 div ,为此分享 html。虽然我同意@Andersson
  • 更新原帖
  • @PeterCook 很清楚你想要一个css-selector 但到底是哪个元素?你想下一步该做什么?提取一些text?哪个文字?

标签: selenium css-selectors


【解决方案1】:

根据您共享的 HTML:

用于获取 div(这真的没有任何意义)

body div:nth-child(2) 

对于 p 节点:

p[ng-bind-html*='policyCancellationInstructions']  

点击这里链接

a[href*='https://www.getaroom.com'] 

我强烈建议您在这种情况下使用 linkText

点击这个号码800-260-3895

a[href*='18002603895']  

点击这个号码0800-012-4507

a[href*='8000124507']

【讨论】:

    【解决方案2】:

    您可以使用下面的 CSS 选择器

    body > div:nth-child(2)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-08-17
      • 1970-01-01
      • 2012-01-20
      • 1970-01-01
      • 2013-06-08
      • 2012-06-22
      相关资源
      最近更新 更多