WebdriverIO перебирает список элементов, используя скрипт Java - PullRequest
0 голосов
/ 01 июня 2018

У меня есть сетка с динамическим количеством строк, и я хочу получить содержимое для каждой строки.ниже приведен пример, и я хочу получить возможность "Это не может быть одной буквой".и «Введите фамилию контактного лица».

Я пытался

var text = $('#topErrorList');

console.log(text.$$('li')[0].$('a').getText()); 
// And
console.log(text.$$('li')[0].getText('a'));

оба не работали

Ошибка: TypeError: Невозможно прочитать свойство 'getText' из неопределенного

 <div id="topErrors">
<h3 id="topErrorTitle">Your information contains 2 error(s).</h3>
<ul id="topErrorList">
    <li>
        <a href="" tabindex="0">This can’t be a single letter.</a>
    </li>
    <li>
        <a href="" tabindex="0">Enter the last name of the contact person.</a>
    </li>
</ul>

1 Ответ

0 голосов
/ 01 июня 2018

Вот как вы можете добиться этого, используя селектор jquery и метод .each().

// Get the title
const contentTitle = $('#topErrorTitle').html().trim();

console.log(contentTitle);


// Get the N Rows texts
const rowContents = [];

// Look at each <a>
$('#topErrorList li a').each(function(elem) {
  // Get the content and push it into the array
  rowContents.push($(this).html().trim());
});

// Display the array
console.log(rowContents);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div id="topErrors">
  <h3 id="topErrorTitle">Your information contains 2 error(s).</h3>

  <ul id="topErrorList">
    <li>
      <a href="" tabindex="0">This can’t be a single letter.</a>
    </li>
    <li>
      <a href="" tabindex="0">Enter the last name of the contact person.</a>
    </li>
  </ul>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...