ai didi

selenium - Selenium 标识符的建议命名约定

转载 作者:行者123 更新时间:2023-12-03 00:35:11 24 4
gpt4 key购买 nike

我使用 selenium 页面对象模型来定义所有页面元素。我对元素命名所遵循的命名约定不太相信,并且感觉太长了。请对此提出建议。

@FindBy(xpath = "//tbody[@id='tabview:listComp1_data']/tr/td[1]/div/div[2]")
public WebElement tableCompanyResultsRow;

@FindBy(xpath = ".//*[@id='mttAddId']")
public WebElement buttonAddMap;

@FindBy(xpath = ".//*[@id='ittAddId']")
public WebElement buttonAddItinerary;

@FindBy(xpath = "//div[@id='ajaxStatusPanel_start']/img")
public WebElement imageLoading;

最佳答案

我长期以来一直使用以下命名约定,它有助于理解和区分 UI 元素。

对于定位器,我总是在变量名称前加上 loc_ 前缀。例如:loc_btnExit

+----------+----------------------------+--------+-----------------+| Category |      UI/Control type       | Prefix |     Example     |+----------+----------------------------+--------+-----------------+| Basic    | Button                     | btn    | btnExit         || Basic    | Check box                  | chk    | chkReadOnly     || Basic    | Combo box                  | cbo    | cboEnglish      || Basic    | Common dialog              | dlg    | dlgFileOpen     || Basic    | Date picker                | dtp    | dtpPublished    || Basic    | Dropdown List / Select tag | ddl    | ddlCountry      || Basic    | Form                       | frm    | frmEntry        || Basic    | Frame                      | fra    | fraLanguage     || Basic    | Image                      | img    | imgIcon         || Basic    | Label                      | lbl    | lblHelpMessage  || Basic    | Links/Anchor Tags          | lnk    | lnkForgotPwd    || Basic    | List box                   | lst    | lstPolicyCodes  || Basic    | Menu                       | mnu    | mnuFileOpen     || Basic    | Radio button / group       | rdo    | rdoGender       || Basic    | RichTextBox                | rtf    | rtfReport       || Basic    | Table                      | tbl    | tblCustomer     || Basic    | TabStrip                   | tab    | tabOptions      || Basic    | Text Area                  | txa    | txaDescription  || Basic    | Text box                   | txt    | txtLastName     || Complex  | Chevron                    | chv    | chvProtocol     || Complex  | Data grid                  | dgd    | dgdTitles       || Complex  | Data list                  | dbl    | dblPublisher    || Complex  | Directory list box         | dir    | dirSource       || Complex  | Drive list box             | drv    | drvTarget       || Complex  | File list box              | fil    | filSource       || Complex  | Panel/Fieldset             | pnl    | pnlGroup        || Complex  | ProgressBar                | prg    | prgLoadFile     || Complex  | Slider                     | sld    | sldScale        || Complex  | Spinner                    | spn    | spnPages        || Complex  | StatusBar                  | sta    | staDateTime     || Complex  | Timer                      | tmr    | tmrAlarm        || Complex  | Toolbar                    | tlb    | tlbActions      || Complex  | TreeView                   | tre    | treOrganization |+----------+----------------------------+--------+-----------------+

关于selenium - Selenium 标识符的建议命名约定,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45028747/

24 4 0
文章推荐: ruby-on-rails - 如何使用 Puma 在 Heroku 上部署 Michael Hartl 的 Rails 教程应用程序
文章推荐: elasticsearch - 如何在术语查询中查询对象数组
文章推荐: powershell - Powershell if语句传递参数
文章推荐: WPF 字符串属性与 Button.Content 的绑定(bind)
行者123
个人简介

我是一名优秀的程序员,十分优秀!

滴滴打车优惠券免费领取
滴滴打车优惠券
全站热门文章
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com