【问题标题】:Finding an element using placeholder in Protractor?在量角器中使用占位符查找元素?
【发布时间】:2019-02-23 05:40:20
【问题描述】:
<input _ngcontent-c6="" formcontrolname="password" 
    name="password" onblur="this.placeholder = 'Password'" 
    onfocus="this.placeholder = ''" 
    placeholder="Password" 
    required="" type="password" 
    ng-reflect-required="" ng-reflect-name="password" 
    class="ng-pristine ng-invalid ng-touched"> 

查找元素的最佳方法是:placeholder = "Enter Username"

场景:使用上面的 Snippet 查找元素 用户点击"Enter Name" 框,弹出另一个输入名称的窗口。

【问题讨论】:

  • css 选择器:input[placeholder="Password"]
  • HTML 指的是placeholder="Password",问题提到了placeholder = "Enter Username",在场景中你提到了"Enter Name"。你的确切用例是什么?

标签: angularjs selenium testing protractor placeholder


【解决方案1】:

对于占位符,您可以使用:

element(by.css('[placeholder = "Password"]'));

【讨论】:

    【解决方案2】:

    你可以像这样使用 XPath:

    .//input[@placeholder='Enter Username']
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多