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?
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
$fruitVal = $I->grabAttributeFrom('#fruit', 'innerHTML');
No longer works.
Use this instead:
$fruitVal = $I->grabTextFrom('#fruit');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With