better popup removal method
All checks were successful
Push image to registry / build-image (push) Successful in 4m50s

This commit is contained in:
2025-06-04 16:21:07 +02:00
parent 31c293e4a6
commit 7e37ea86d0

View File

@ -304,7 +304,7 @@ class InstagramRepostJob extends BrowserJob implements ShouldBeUniqueUntilProces
sleep(2); sleep(2);
$browser->attach('input[type="file"]._ac69', $this->downloadFolder . $reel->reel_id . ".mp4"); $browser->attach('input[type="file"]._ac69', $this->downloadFolder . $reel->reel_id . ".mp4");
sleep(5); // TODO : Wait for the file to be uploaded sleep(10); // TODO : Wait for the file to be uploaded
$this->removePopups($browser); $this->removePopups($browser);
sleep(2); sleep(2);
@ -340,13 +340,13 @@ class InstagramRepostJob extends BrowserJob implements ShouldBeUniqueUntilProces
try { try {
$browser->waitForText("Your post was shared", 60, true); $browser->waitForText("Your post was shared", 60, true);
$closeButton = $browser->driver->findElement(WebDriverBy::xpath('//div[./div/*[local-name() = "svg"][@aria-label="Close"]]')); $closeButton = $browser->driver->findElement(WebDriverBy::xpath('//div[./div/*[local-name() = "svg"][@aria-label="Close"]]'));
$closeButton->click();
} catch (\Exception $e) { } catch (\Exception $e) {
// Do nothing Log::error("Failed to repost reel: {$reel->reel_id} - " . $e->getMessage());
$browser->screenshot(JobDebugScreenshot::getFileName($this->jobId));
AllNotification::send(new JobDebugNotification($this->jobId, "Failed to repost reel: {$reel->reel_id} - " . $e->getMessage()));
$closeButton->click();
} }
Log::error("Failed to repost reel: {$reel->reel_id} - " . $e->getMessage());
$browser->screenshot(JobDebugScreenshot::getFileName($this->jobId));
AllNotification::send(new JobDebugNotification($this->jobId, "Failed to repost reel: {$reel->reel_id} - " . $e->getMessage()));
return false; return false;
} }
@ -406,35 +406,28 @@ class InstagramRepostJob extends BrowserJob implements ShouldBeUniqueUntilProces
protected function removePopups(Browser $browser) protected function removePopups(Browser $browser)
{ {
try { $popupsTypes = [
$cookiesAllowButton = $browser->driver->findElement(WebDriverBy::xpath('//button[contains(text(), "Allow all cookies")]')); ['//button[contains(text(), "Allow all cookies")]'], // Allow all cookies
$cookiesAllowButton->click(); ['//button[contains(text(), "Not Now")]', ["Popup Not Now clicked"]], // Not now
sleep(2); ['//button[contains(text(), "OK")]', ["Popup Ok clicked"]], // OK
} catch (\Exception $e) { ];
// No cookie popup found, continue
}
try { foreach ($popupsTypes as $popup) {
$notNowButton = $browser->driver->findElement(WebDriverBy::xpath('//button[contains(text(), "Not Now")]')); try {
$notNowButton->click(); $button = $browser->driver->findElement(WebDriverBy::xpath($popup[0]));
$browser->screenshot(JobDebugScreenshot::getFileName($this->jobId)); if ($button === null) {
AllNotification::send(new JobDebugNotification($this->jobId, "Popup Not Now clicked")); continue; // No button found, continue to the next popup
sleep(2); }
} catch (\Exception $e) { if (isset($popup[1])) {
// No "Not Now" popup found, continue $browser->screenshot(JobDebugScreenshot::getFileName($this->jobId));
AllNotification::send(new JobDebugNotification($this->jobId, $popup[1][0]));
}
$button->click();
sleep(2);
return; // Exit after clicking the first popup found
} catch (\Exception $e) {
// Porbably no popup found, continue
}
} }
try {
$okButton = $browser->driver->findElement(WebDriverBy::xpath('//button[contains(text(), "OK")]'));
$okButton->click();
$browser->screenshot(JobDebugScreenshot::getFileName($this->jobId));
AllNotification::send(new JobDebugNotification($this->jobId, "Popup Ok clicked"));
sleep(2);
} catch (\Exception $e) {
// No "Ok" popup found, continue
}
// $browser->script('document.querySelector("div.app-modal")[0].remove();');
// $browser->driver->executeScript('document.querySelector("div.app-modal")[0].remove();');
} }
} }