Код: Выделить всё
upload picture
Open new window
Uploaded images will appear below:
let uploadCount = 0;
document.getElementById('openWindow').onclick = function() {
const newWindow = window.open('upload.html', 'Upload Image', 'width=500,height=500');
newWindow.focus();
};
window.addEventListener('message', function(event) {
if (event.origin !== window.location.origin) {
alert('Data from unknown sources!');
return;
}
uploadCount++;
const imageURL = event.data;
if (uploadCount === 1) {
document.getElementById('uploadedImage1').src = imageURL;
} else if (uploadCount === 2) {
document.getElementById('uploadedImage2').src = imageURL;
}
});
Код: Выделить всё
upload picture2
window.onload = function() {
alert('Please select a picture and upload it!');
};
upload
document.getElementById('uploadButton').onclick = function() {
const fileInput = document.getElementById('fileInput');
if (fileInput.files.length === 0) {
alert('Please select a profile!');
return;
}
const file = fileInput.files[0];
const reader = new FileReader();
reader.onload = function(e) {
window.opener.postMessage(e.target.result, window.opener.location.origin);
window.close();
};
reader.readAsDataURL(file);
};
Код: Выделить всё
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
service = Service('/usr/local/bin/chromedriver')
options = Options()
options.add_experimental_option('detach', True)
driver = webdriver.Chrome(service=service, options=options)
driver.get('http://127.0.0.1:5500/index.html')
open_window_button = driver.find_element(By.ID, 'openWindow')
open_window_button.click()
time.sleep(2)
print('sleep is over.')
# This is the point where the process stops each time to check or look for the alert window.
file_input = WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.ID, 'fileInput')))
file_path = ''
file_input.send_keys(file_path)
upload_button = driver.find_element(By.ID, 'uploadButton')
upload_button.click()
обновите страницу после входа на второй веб-сайт, чтобы повторно захватить текущее окно, увеличьте время ожидания для захвата содержимого всплывающего окна и переключитесь вернемся к главному окну выполнения...
Пока ни один из этих методов не может захватить новое окно и всплывающее окно с предупреждением. Если я вручную взаимодействую с оповещением во время процесса автоматизации, только тогда я смогу записать новую страницу браузера.
Подробнее здесь: https://stackoverflow.com/questions/785 ... the-second