css选择器 自定义属性_使用CSS选择器和自定义属性升级项目

css选择器 自定义属性

This article was originally published by TestProject. Thank you for supporting the partners who make SitePoint possible.

本文最初由TestProject发布。 感谢您支持使SitePoint成为可能的合作伙伴。

Element selectors for Selenium WebDriver are one of the core components of an automation framework and are the key to interaction with any web application. In this review of automation element selectors, we will discuss the various strategies, explore their capabilities, weigh their pros and cons, and eventually recommend the best selector strategy – custom attributes with CSS selector.

Selenium WebDriver的元素选择器是自动化框架的核心组件之一,并且是与任何Web应用程序进行交互的关键。 在这篇自动化元素选择器的回顾中,我们将讨论各种策略,探讨它们的功能,权衡其优缺点,并最终推荐最佳选择器策略 -CSS选择器的自定义属性。

Selenium元素选择器 (Selenium Element Selectors)

Choosing the best element selector strategy is critical to the success and ease of maintenance of your automation effort. Therefore, when choosing your selector, you should consider aspects such as ease of use, versatility, online support, documentation and performance. Strong consideration for a proper selector strategy will pay dividends in the future through easy to maintain automation.

选择最佳的元素选择器策略对于自动化工作的成功和易于维护至关重要。 因此,在选择选择器时,应考虑诸如易用性,多功能性,在线支持,文档和性能等方面。 认真考虑适当的选择器策略,将通过易于维护的自动化在未来带来回报。

Just as the technological aspect of element selectors should be considered, so too should the culture of your organization. A mature culture of collaboration between developers and QA will unlock high tiers of success when implementing element selectors in your automation. This benefits the organization beyond just the automation effort by laying the foundation for collaboration in other areas of the Software Development Life Cycle.

正如应考虑元素选择器的技术方面一样,组织的文化也应考虑在内。 在自动化中实现元素选择器时,开发人员和质量保证人员之间成熟的协作文化将释放出巨大的成功。 通过为软件开发生命周期其他领域的协作奠定基础,这不仅使自动化工作受益,还使组织受益。

All code examples will be in Python and Selenium WebDriver commands but should be generally applicable to any programming language and framework.

所有代码示例都将使用PythonSelenium WebDriver命令,但通常应适用于任何编程语言和框架。

HTML示例: (HTML Example:)

I will use the following HTML snippet of a navigation menu for examples in each section:

我将在每个部分的示例中使用以下导航菜单HTML代码段:

<div id="main-menu">
  <div class="menu"><a href="/home">Home</a></div>
  <div class="menu"><a href="/shop">Shop</a>
    <div class="submenu">
      <a href="/shop/gizmo">Gizmo</a>
      <a href="/shop/widget">Widget</a>
      <a href="/shop/sprocket">Sprocket</a>
    </div>
  </div>
</div>

错误:标记名称,链接文本,部分链接文本和名称 (Bad: Tag Name, Link Text, Partial Link Text and Name)

I won’t spend too much time on these because they all have limited use. They are generally not a good option for wide adoption across the entire automation framework. They solve specific needs that can be easily covered with other element selector strategies. Only use these if you have a specific need to handle a special case. Even then, most special cases are not special enough to use these. You would use these in a scenario where there is no other selector option available to you (such as custom tags or id).

我不会在这些产品上花费太多时间,因为它们的用途有限。 通常,它们不是在整个自动化框架中广泛采用的好选择。 他们解决了其他元素选择器策略可以轻松满足的特定需求。 仅在有特殊需要时才使用这些。 即使这样,大多数特殊情况仍不足以使用这些特殊情况。 您将在没有其他选择器选项(例如自定义标签或ID)可用的情况下使用它们。

例: (Example:)

With tag name, you can select large groups of elements that all match the tag name you provided. This has lim

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值