PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, February 3, 2022

[FIXED] Laravel Dusk: How to get HTML from element?

 February 03, 2022     laravel, laravel-5, laravel-dusk     No comments   

Issue

I understand that you can get the text from an element, like this:

$text = $browser->text('.selector');

My question is: How can you get the raw HTML content? E.g. the following doesn't work

$text = $browser->html('.selector');

E.g. if the element is:

<div class='selector'><p>Hello</p></div>

I'd like to get the following as the output (with the < p> tags):

<p>Hello</p>

Thanks


Solution

To get the source code of your element you should use the element() method together with the getAttribute() like this:

$html = $browser->element('.selector')->getAttribute('innerHTML');
// now in $html you have HTML inside .selector element


Answered By - Christopher Dosin
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing