Skip to content

Commit

Permalink
Make example XPath filter more specific when selecting element to click
Browse files Browse the repository at this point in the history
  • Loading branch information
kkamara committed Mar 24, 2024
1 parent e7be797 commit 7b92916
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion app/Console/Commands/BrowserScrape.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ public function handle()
$crawler = $this->client->getCrawler();
$preferences = $crawler->filterXPath('//button[@data-testid="accept-button"]');
$preferences->click();
$element = $crawler->filterXPath('//h3[text()="1. Kenneth Branagh"]');
$element = $crawler->filterXPath(
'//div[@data-testid="nlib-title"][contains(@class, "ipc-title")]/a[@class="ipc-title-link-wrapper"]/h3[text()="1. Kenneth Branagh"]'
);
$element->click();
$this->client->takeScreenshot('screenshot.jpg');

Expand Down
4 changes: 3 additions & 1 deletion storage/app/NewCrawler2024.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ public function handle()
$crawler = $this->client->getCrawler();
$preferences = $crawler->filterXPath('//button[@data-testid="accept-button"]');
$preferences->click();
$element = $crawler->filterXPath('//h3[text()="1. Kenneth Branagh"]');
$element = $crawler->filterXPath(
'//div[@data-testid="nlib-title"][contains(@class, "ipc-title")]/a[@class="ipc-title-link-wrapper"]/h3[text()="1. Kenneth Branagh"]'
);
$element->click();
$this->client->takeScreenshot('screenshot.jpg');

Expand Down

0 comments on commit 7b92916

Please sign in to comment.