duanjue9296 2015-12-08 08:14
浏览 15
已采纳

如何用代码获取元素?

Let's say we have a following html code:

<div>
  <p id="fruit">Apple</p>
</div>

How to grab #fruit and check its inner html via codeception?

  • 写回答

1条回答 默认 最新

  • douhe6255 2015-12-08 08:33
    关注

    It seems, that Codeception utilizes either executeJS or executeInSelenium(not recommended) in these kind of situations.

    Here is an example using executeJS with JQuery:

    <?php
      $fruitVal = $I->executeJS('return $(#fruit).val()');
    ?>
    

    See more in: Codeception docs: executeJS


    Turns out, that there is another, "more natural" way to handle this case:

    Here is an example using grabAttributeFrom method:

    <?php
      $fruitVal = $I->grabAttributeFrom('#fruit', 'innerHTML');
    ?>
    

    See more in: Codeception docs: grabAttributeFrom

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样