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

时间:2016-06-29 13:42:41

标签: intern leadfoot

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;
});

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

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

单击按钮后会创建一个表格。我想得到这张桌子。

<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>

1 个答案:

答案 0 :(得分:1)

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

.getProperty("innerHTML")表示该div中的源数据