Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can an element be grabbed with codeception?

Let's say we have the following HTML code:

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

How do I grab #fruit and check its inner HTML via codeception?

like image 527
Alex Lomia Avatar asked Nov 17 '25 05:11

Alex Lomia


2 Answers

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

like image 188
Alex Lomia Avatar answered Nov 18 '25 17:11

Alex Lomia


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

No longer works.

Use this instead:

$fruitVal = $I->grabTextFrom('#fruit');
like image 25
Robert Sinclair Avatar answered Nov 18 '25 18:11

Robert Sinclair



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!