Selenium获取子元素或getText()

时间:2017-07-03 11:02:22

标签: selenium automation protractor

我是Selenium和Protractor的新手。我有以下代码:

<button id="createPage" data-button-error="true" class="concierge-button button error is-disabled" data-ng-disabled="!newPageReady" data-ng-class="{ 'error': errors.button, 'is-disabled error' : errors.button  }" data-ng-click="createnewstudioitem(designerItems[0], conciergetitle, $event)" style="">

<div class="summary">
  <label class="error ng-binding ng-scope" data-ng-if="errors.error || errors.category" data-ng-bind="errors.message">Remove special characters</label>
</div>

我正在使用硒和量角器。我正在尝试 获取data-button-error="true"的值,或者我正在尝试查看是否存在oerds Remove special characters。原因是我要验证是否添加了特殊字符,有Remove special characters消息data-button-error="true"false更改为true

我试过了:

        var addSpecialText = element.all(by.css(".error")).first();;
        expect(addSpecialText.getText()).toEqual('Remove special characters');

        var addSpecialText = element.all(by.css(".error"));
        expect(addSpecialText.get(0).getText()).toEqual('Remove special characters');

            var addSpecialText = element.all(by.css(".error")).getAttribute("innerText");

1 个答案:

答案 0 :(得分:2)

使用selenium获取数据按钮错误:

String data = driver.findElement(By.id("createPage")).getAttribute("data-button-error");

获取&#34;删除特殊字符&#34;使用硒:

String data = driver.findElement(By.cssSelector(".summary label")).getText();