Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.10] Add Node::setHTML #538

Merged
merged 1 commit into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/Dom/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,17 @@ public function getHTML(): string
return $response->getResultData('outerHTML');
}

public function setHTML(string $outerHTML): void
{
$message = new Message('DOM.setOuterHTML', [
'nodeId' => $this->nodeId,
'outerHTML' => $outerHTML,
]);
$response = $this->page->getSession()->sendMessageSync($message);

$this->assertNotError($response);
}

public function getText(): string
{
return \strip_tags($this->getHTML());
Expand Down
14 changes: 14 additions & 0 deletions tests/DomTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,18 @@ public function testUploadFiles(): void
self::assertStringEndsWith(\basename($files[0]), $value1);
self::assertStringEndsWith(\basename($files[1]), $value2);
}

public function testSetHTML(): void
{
$page = $this->openSitePage('domForm.html');

$element = $page->dom()->querySelector('#div1');
$element->setHTML('<span id="span">hello</span>');

$value = $page->dom()->querySelector('#span')->getHTML();

self::assertCount(0, $page->dom()->querySelectorAll('#div1'));

self::assertEquals('<span id="span">hello</span>', $value);
}
}