【问题标题】:css locator to navigate to parent tag from child and css locator to identify sub string in a attributecss定位器从子标签导航到父标签,css定位器识别属性中的子字符串
【发布时间】:2023-03-30 03:02:01
【问题描述】:

我擅长编写 XPATH 定位器,但对于我的新项目,我必须使用 CSS 编写定位器

我有两个疑问

1)

从上面的代码中,我必须用 id 识别 div 包含值“col3

xpath 我可以写 //div[contains(@id,'col3')]

css 我尝试了下面的定位器

css=#id:contains('col3')

css=div:contains(#id,'col3') 但他们都没有工作。

请帮助我使用 CSS 定位器来识别 id 包含值“col3

2)

我必须从一个属性导航到其父属性。

即,从“表单标签我必须导航到它的父 div 标签”

XPATH //form[@id='comment-form']/../

帮助我使用 CSS

进行导航

【问题讨论】:

    标签: html selenium xpath selenium-webdriver css-selectors


    【解决方案1】:

    你能试试这个第一个吗 css=div[id*='col3']

    【讨论】:

      【解决方案2】:

      第一个问题的解决方案是:

      div[id*='col3'] 
      

      参考Is there a CSS parent selector?,我认为您的第二个问题没有任何解决方案。您可能必须在此处使用 xpath。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-05-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-10-04
        • 2018-01-16
        • 2018-09-04
        相关资源
        最近更新 更多