在使用selenium多开浏览器(同chrome多个),
但每个网页加载的时间尽不相同
所以操作下一步时每个开始的时间不一样
我想问能不能让前面做完某步的浏览器等全部浏览器跑完再一起进行下一步
ex: 第一个网页点完按钮,等待2,3...n个浏览器都点完按钮在执行点下一个按钮的动作。
我的代码示例如下
from datetime import datetime
from selenium import webdriver
import threading
from multiprocessing import Queue
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
def selenium_mult():
chrome_options = Options()
chrome_options.add_argument("--headless")
ser=Service('./chromedriver')
driver = webdriver.Chrome(service = ser,options=chrome_options)
driver.set_window_size(540,480)
driver.get('https:/website')
WebDriverWait(driver,10,1).until(EC.visibility_of_element_located((By.XPATH, '//*[@id="btn"]/div/div[3]/button[1]')))
driver.find_element(By.XPATH, '//*[@id="btn"]/div/div[3]/button[1]').click() #click button 1
Ftime = datetime.now()
WebDriverWait(driver,30,1).until(EC.visibility_of_element_located((By.XPATH, '//*[@id="btn"]/div/div[2]/div[1]/div[6]/div')))
driver.find_element(By.XPATH, '//*[@id="btn"]/div/div[2]/div[1]/div[6]/div').click() #click button 2
if __name__ == '__main__':
for i in range(5):
t = threading.Thread(target=selenium_mult)
t.start()