首页 > 解决方案 > 如何同时运行两个 selenium python 程序

问题描述

我想同时运行代码两次以节省时间。我是一个初学者,我正在对此进行一些研究并获得多线程这个词并听说过 pytest 库,但我不知道如何做到这一点,甚至我找不到示例代码。请帮我!我等着你的回答

import selenium
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from shutil import which
import time
import pandas as pd
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.common.exceptions import TimeoutException
Links = []
chrome_path = which('chromedriver')
driver = webdriver.Chrome(executable_path=chrome_path)
driver.maximize_window()

driver.get('https://www.google.com')

text = driver.find_element_by_xpath('//input[@class="gLFyf gsfi"]')
text.send_keys('Hello')

driver.find_element_by_xpath('//div[@class="FPdoLc tfB0Bf"]//input[1]').click()
time.sleep(3)

driver.close()

我想同时跑两次?任何人帮助我

标签: javapythonseleniumselenium-webdriver

解决方案


您始终可以使用“Jupyter Notebooks”,然后您可以使用新名称另存为脚本并同时运行它们。


推荐阅读