Транспортир - Как получить доступ к дочерним элементам в родительском элементе - PullRequest
0 голосов
/ 11 сентября 2018

Я пытаюсь получить доступ к метке, содержащейся в строке.

Этот код работает, однако он находит все метки этого типа вместо одной в определенной / родительской строке:

expect(element(by.xpath("//span[@ng-click='location.viewAudit(audit)'][contains(@class, 'source-name')]")).isPresent()); //label for the source name

Это код для меня:

var tableRow = element(by.xpath("//tr[contains(@class, 'ng-scope')][@ng-repeat='audit in location.displayedProfileAudits']")).getWebElement();
expect(tableRow.element(by.xpath("//span[@ng-click='location.viewAudit(audit)'][contains(@class, 'source-name')]")).isPresent()); //label for the source name 

и возвращаемая ошибка:

Message: TypeError: tableRow.element is not a function

Определение шага полностью:

Then('I should see that a location audit source row has a label for the source', function (callback) {
    browser.wait(EC.visibilityOf(listingsPageObj.locationProfileListViewContainer), timeouts.EC_TIMEOUT).then(() => {
        browser.wait(EC.visibilityOf(listingsPageObj.locationProfileListViewTable), timeouts.EC_TIMEOUT).then(() => {
            browser.wait(() => {
                return listingsPageObj.locationProfileListViewTableHeaders.count().then(cnt => (cnt > 0)); //which means that there are audit results displayed
            }).then(() => {
                //find a row in the list of displayed audits
                var tableRow = element(by.xpath("//tr[contains(@class, 'ng-scope')][@ng-repeat='audit in location.displayedProfileAudits']")).getWebElement();
                //then verify, within that row, there is a label for the source name
                expect(tableRow.element(by.xpath("//span[@ng-click='location.viewAudit(audit)'][contains(@class, 'source-name')]")).isPresent()); //label for the source name 

                callback();
            });
        });
    });
});

Ответы [ 2 ]

0 голосов
/ 12 сентября 2018

Вам нужно добавить точку . в заголовке вашего xpath, как показано ниже. . здесь означает текущий узел, который является предыдущим tableRow, это изменит контекст поиска в текущем узле tableRow. Без . в заголовке // означает, что контекст поиска - это целая страница, поэтому вы найдете все метки этого типа.

На самом деле вы можете удалить tableRow из tableRow.element..., если нет . в заголовке //span[....]

expect(tableRow.element(by.xpath(
    ".//span[@ng-click='location.viewAudit(audit)'][contains(@class, 'source-name')]"))
.isPresent());
0 голосов
/ 11 сентября 2018
Then('I should see that a location audit source row has a label for the source', function (callback) {
    browser.wait(EC.visibilityOf(listingsPageObj.locationProfileListViewContainer), timeouts.EC_TIMEOUT).then(() => {
        browser.wait(EC.visibilityOf(listingsPageObj.locationProfileListViewTable), timeouts.EC_TIMEOUT).then(() => {
            browser.wait(() => {
                return listingsPageObj.locationProfileListViewTableHeaders.count().then(cnt => (cnt > 0)); //which means that there are audit results displayed
            }).then(() => {
                //find a row in the list of displayed audits
                var tableRow = element(by.xpath("//tr[contains(@class, 'ng-scope')][@ng-repeat='audit in location.displayedProfileAudits']"));
                //then verify, within that row, there is a label for the source name
                expect(tableRow.element(by.xpath("//span[@ng-click='location.viewAudit(audit)'][contains(@class, 'source-name')]")).isPresent()); //label for the source name 
                callback();
            });
        });
    });
});
...