better popup removal method
All checks were successful
Push image to registry / build-image (push) Successful in 4m50s
All checks were successful
Push image to registry / build-image (push) Successful in 4m50s
This commit is contained in:
@ -304,7 +304,7 @@ class InstagramRepostJob extends BrowserJob implements ShouldBeUniqueUntilProces
|
||||
sleep(2);
|
||||
$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);
|
||||
sleep(2);
|
||||
@ -340,13 +340,13 @@ class InstagramRepostJob extends BrowserJob implements ShouldBeUniqueUntilProces
|
||||
try {
|
||||
$browser->waitForText("Your post was shared", 60, true);
|
||||
$closeButton = $browser->driver->findElement(WebDriverBy::xpath('//div[./div/*[local-name() = "svg"][@aria-label="Close"]]'));
|
||||
$closeButton->click();
|
||||
|
||||
} 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;
|
||||
}
|
||||
@ -406,35 +406,28 @@ class InstagramRepostJob extends BrowserJob implements ShouldBeUniqueUntilProces
|
||||
|
||||
protected function removePopups(Browser $browser)
|
||||
{
|
||||
try {
|
||||
$cookiesAllowButton = $browser->driver->findElement(WebDriverBy::xpath('//button[contains(text(), "Allow all cookies")]'));
|
||||
$cookiesAllowButton->click();
|
||||
sleep(2);
|
||||
} catch (\Exception $e) {
|
||||
// No cookie popup found, continue
|
||||
}
|
||||
$popupsTypes = [
|
||||
['//button[contains(text(), "Allow all cookies")]'], // Allow all cookies
|
||||
['//button[contains(text(), "Not Now")]', ["Popup Not Now clicked"]], // Not now
|
||||
['//button[contains(text(), "OK")]', ["Popup Ok clicked"]], // OK
|
||||
];
|
||||
|
||||
try {
|
||||
$notNowButton = $browser->driver->findElement(WebDriverBy::xpath('//button[contains(text(), "Not Now")]'));
|
||||
$notNowButton->click();
|
||||
$browser->screenshot(JobDebugScreenshot::getFileName($this->jobId));
|
||||
AllNotification::send(new JobDebugNotification($this->jobId, "Popup Not Now clicked"));
|
||||
sleep(2);
|
||||
} catch (\Exception $e) {
|
||||
// No "Not Now" popup found, continue
|
||||
foreach ($popupsTypes as $popup) {
|
||||
try {
|
||||
$button = $browser->driver->findElement(WebDriverBy::xpath($popup[0]));
|
||||
if ($button === null) {
|
||||
continue; // No button found, continue to the next popup
|
||||
}
|
||||
if (isset($popup[1])) {
|
||||
$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();');
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user