量角器中的动态属性值元素定位器

时间:2017-02-22 07:23:44

标签: javascript function attributes protractor

当我添加一个带有某个值的新按钮时,它会动态添加到DOM中。此按钮的非Angular HTML元素为:

<li class="ui-state-default droppable ui-sortable-handle" id="element_98" data-value="2519">
    25.19 EUR
<button type="button" class="btn btn-default removeParent">
<span class="glyphicon glyphicon-remove" aria-hidden="true">
</span>
</button>
</li>

一旦我删除此按钮,我想检查它不再存在。我正在搜索的元素是data-value="2519",这可能是我设置的任何内容,例如2000,1000,500,1050 ......

在页面对象文件中,我尝试使用以下内容:

this.newValueButtonIsNotPresent = function(item) {
        newValueButton = browser.element(by.id("containerQUICK_ADD_POINTS")).all(by.css('[data-value="' + item + '"]'));
        return newValueButton.not.isPresent();
    };

在spec文件中,我将此函数调用如下:

var twentyEurosButtonAttributeValue = '2000';

describe("....
    it ("...
        expect(predefined.newValueButtonIsNotPresent(twentyEurosButtonAttributeValue)).toBeTruthy();

我知道这不正确,但我怎么能做到这样的事情还是有另一种方式?

1 个答案:

答案 0 :(得分:1)

愚蠢的我,我找到了一个简单的解决方案。而是动态地定位我位于列表中的第一个元素,该元素始终是新添加的元素,然后检查它是否与文本不匹配:

页面对象文件:

USE [Curatas_Live]
GO
/****** Object:  UserDefinedFunction [dbo].[BreakStringIntoRows]    Script Date: 22-02-2017 12:52:32 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER FUNCTION [dbo].[BreakStringIntoRows] (@CommadelimitedString   varchar(1000))
RETURNS  [@Result   VARCHAR(100)]
AS
BEGIN
         declare @result VARCHAR(100)
           DECLARE @IntLocation INT
    DECLARE @ResultCode VARCHAR(100)
    SET @Result = ''
        WHILE (CHARINDEX(',',    @CommadelimitedString, 0) > 0)
        BEGIN
              SET @IntLocation =   CHARINDEX(',',    @CommadelimitedString, 0)      



          SELECT @ResultCode = RTRIM(LTRIM(SUBSTRING(@CommadelimitedString,   0, @IntLocation))) 
     SELECT @Result =@Result + ITMSGRPNAME FROM OITB
     WHERE ITMSGRPCODE=@ResultCode

          SET @CommadelimitedString = STUFF(@CommadelimitedString,   1, @IntLocation,   '') 
    END

    SELECT @ResultCode = RTRIM(LTRIM(@CommadelimitedString))--LTRIM and RTRIM to ensure blank spaces are removed
SELECT @Result =@Result + ITMSGRPNAME FROM OITB
     WHERE ITMSGRPCODE=@ResultCode
    RETURN @Result
END

规格文件:

this.newValueButtonIsNotPresent = function() {
        newValueButton = browser.element(by.id("containerQUICK_ADD_POINTS")).all(by.tagName('li')).first();
        return newValueButton.getText();
    };