Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- async function retryOperation(operation, maxRetries = 3, delay = 5000) {
- for (let attempt = 1; attempt <= maxRetries; attempt++) {
- try {
- return await operation();
- } catch (error) {
- console.log(`Attempt ${attempt} failed: ${error.message}`);
- if (attempt === maxRetries) {
- throw new Error(`Operation failed after ${maxRetries} attempts: ${error.message}`);
- }
- console.log(`Retrying in ${delay / 1000} seconds...`);
- await new Promise(resolve => setTimeout(resolve, delay));
- }
- }
- }
- // Usage example for waitForSelector
- try {
- const input = await retryOperation(
- () => page.waitForSelector('#kodWydzialuInput', { timeout: 30000 }),
- 3, // maxRetries
- 5000 // delay
- );
- // Continue with your code using the input element
- } catch (error) {
- console.error('Error:', error.message);
- // Handle the error
- }
Advertisement
Add Comment
Please, Sign In to add comment