【问题标题】:How to get H1 tag value under a class如何获取类下的H1标签值
【发布时间】:2018-12-07 21:41:06
【问题描述】:

我希望在名为“inner”的类中获取“Testing 2”文本,如下所示。

<div _ngcontent-c6="" class="inner">
    <h1 _ngcontent-c6=""> Testing 2
    </h1>
</div>

我试过“return element(by.css('.inner')).element(by.css("h1")).getText();”和“返回元素(by.className('inner')).element(by.css(“h1”)).getText();”但两个代码都不起作用。

在运行上述代码时,我遇到了同样的错误:“失败:使用定位器找不到元素:By(css selector, h1)”

如何在具有类名的 div 中获取 h1 的值?

【问题讨论】:

    标签: protractor


    【解决方案1】:

    请稍等片刻。

    var EC = protractor.ExpectedConditions;
    var target = element(by.css('div.inner > h1'));
    
    browser.wait(EC.presenceOf(target), 15*1000);
    
    target.getText().then(function(txt){
        console.log('H1: ' + txt);
    });
    

    【讨论】:

      猜你喜欢
      • 2016-05-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-03
      • 1970-01-01
      • 2012-12-28
      相关资源
      最近更新 更多