代码之家  ›  专栏  ›  技术社区  ›  asus

从coffeescript/selenium中的唯一父级访问内部子选择器

  •  1
  • asus  · 技术社区  · 6 年前

    我正在使用coffeescript.js和chai框架在Selenium中编写一个测试,以选择一个内部子元素,其中父元素具有唯一的类名。

    子元素通过应用程序重用,并且不唯一,因此我需要将父元素的名称用作唯一定位器。

    portals-client_uu portals is the parent element I want to use to reference toggles_u name.>code>

    “created_portal_in_super”:。{
    “xpath”:“//span[包含(@class,'切换名称')]
    }
    < /代码> 
    
    

    正确的嵌套方法是什么?

    我知道对于表格,可以使用诸如tbody>tr>td之类的内容,但我不确定如何在上面的示例中实现这一点。

    子元素通过应用程序重用,并且不唯一,因此我需要将父元素的名称用作唯一定位器。

    example

    portals-client__portals是要用于引用的父元素toggles__name

      "created_portal_in_super": {
        "xpath": "//span[contains(@class,'toggles__name')]"
      }
    

    正确的嵌套方法是什么?

    我知道桌子之类的tbody > tr > td可以使用,但在上面的示例中,我不确定如何使其工作。

    2 回复  |  直到 6 年前
        1
  •  1
  •   Andersson    6 年前

    尝试使用此xpath:

    //div[contains(@class, "portals-client__portals")]//span[@class="toggles__name"]
    
        2
  •  1
  •   Sers    6 年前

    CSS选择器:

    .portals-client__portals span.toggles__name