如何从divHTML标签获取页面源数据?

How to get page source data from div HTML tag?

Intern/Leadfoot 中是否有从 <div> HTML 标签中获取源内容或至少原始文本的方法?

我在下面的参考资料中找过,但没有成功。 https://theintern.github.io/leadfoot/module-leadfoot_Command.html

下面你可以看到我的一段代码。它执行无误。但是 console.log(text) 显示 undefined.

/*global define*/
define(function (require) {

  function Datasource (remote) {
    this.remote = remote;
  }

  Datasource.prototype = {
    constructor: Datasource,

    queryDatasource: function (kibiUrl, title, description, datasource, query) {
      return this.remote
        .get(require.toUrl(kibiUrl))
        .setFindTimeout(3000)
        .sleep(3000)
        .findByCssSelector('input[ng-model="query.title"]')
          .clearValue()
          .type(title)
          .end()
        .findByCssSelector('input[ng-model="query.description"]')
          .type(description)
          .end()
        .findByCssSelector('option[label="'+ datasource +'"]')
          .click()
          .end()
        .findByName('sqlQuery')
        .findByClassName('ace_text-input')
          .type(query)
          .end()
        .findByXpath('//button[@class="btn btn-success"]')
          .click()
          .end()
        .sleep(3000)
        .acceptAlert()
          .end()
        .findByCssSelector('div[class="html_preview_content"]')
        .getVisibleText()
        .then(function (text) {
          console.log("SOURCE");
          console.log(text);
          return text;
        });
    }

  };

  return Datasource;
});

从一开始就可见。页面上只有一个 div html_preview_content class。

一开始是空的。 <div class="html_preview_content" kibi-dynamic-html="holder.htmlPreview"></div>

单击按钮后会创建一个 table。我想得到这个 table.

<div class="html_preview_content" kibi-dynamic-html="holder.htmlPreview">
   <style class="ng-scope">thead.custome-header thead{color:#black;}</style>
   <a href="javascript:showHide('ad90128b-0275-4f95-bda9-78e9a5e9771f');" id="button-ad90128b-0275-4f95-bda9-78e9a5e9771f" class="snippetShowHideButton ng-scope">- Hide </a><span class="ng-scope"> </span>
   <span class="snippetLabel ng-scope">Preview</span><span class="ng-scope"> (15) </span>
   <div id="cont-ad90128b-0275-4f95-bda9-78e9a5e9771f" style="display:block" class="ng-scope">
      <table class="table table-condensed custome-header">
         <thead>
            <tr>
               <th>Tables_in_crunchbase</th>
            </tr>
         </thead>
         <tbody>
            <tr>
               <td>article</td>
            </tr>
            <tr>
               <td>article_company</td>
            </tr>
            <tr>
               <td>company</td>
            </tr>
            <tr>
               <td>company_city</td>
            </tr>
            <tr>
               <td>company_competitor</td>
            </tr>
            <tr>
               <td>company_countrycode</td>
            </tr>
            <tr>
               <td>company_geolocation</td>
            </tr>
            <tr>
               <td>company_investment</td>
            </tr>
            <tr>
               <td>company_statecode</td>
            </tr>
            <tr>
               <td>investment</td>
            </tr>
            <tr>
               <td>investment_investor</td>
            </tr>
            <tr>
               <td>investor</td>
            </tr>
            <tr>
               <td>investor_city</td>
            </tr>
            <tr>
               <td>investor_countrycode</td>
            </tr>
            <tr>
               <td>investor_statecode</td>
            </tr>
         </tbody>
      </table>
   </div>
</div>

您可以使用 .findByCssSelector('div[class="html_preview_content"]').getProperty("outerHTML") 获取 html_preview_content div.

的源数据

.getProperty("innerHTML")用于div

中的源数据