[英]How do I use multiple browser instances at the same time in selenium python?
I have a code that opens three same windows of website, and I need to do the same actions on them at the same time, is it possible?我有一个代码可以打开三个相同的网站窗口,我需要同时对它们执行相同的操作,这可能吗? If yes, how can I make it?
如果是,我该怎么做? Btw, I am new to selenium, and programming at all, so sorry for a dumb question :d Thanks for any help.
顺便说一句,我是 selenium 和编程的新手,很抱歉问一个愚蠢的问题 :d 感谢您的帮助。
Upd.更新。 I've tried using something like this, and now actions are being made only at one window, what should I do?
我试过使用这样的东西,现在只能在一个窗口中进行操作,我该怎么办?
browser_list = []
browser1 = webdriver.chrome()
browser2 = webdriver.chrome()
browser3 = webdriver.chrome()
browser_list.append(browser1)
browser_list.append(browser2)
browser_list.append(browser3)
for browser in browser_list:
browser.get("link")
def akfqv():
while True:
browser1.find_element_by_xpath('')\
.click()
def adkq():
while True:
browser2.find_element_by_xpath('')\
.click()
def djqd():
while True:
browser3.find_element_by_xpath('')\
.click()
thread1 = Thread(target=akfqv())
thread1 = Thread(target=adkq())
thread1 = Thread(target=djqd())
thread1.start()
thread2.start()
thread3.start()
you can use list of webdriver and loop for each element您可以为每个元素使用 webdriver 和循环列表
for example:例如:
from selenium import webdriver
li=[]
li.append(webdriver.Chrome())
li.append(webdriver.Chrome())
li.append(webdriver.Chrome())
for i in li:
i.get("https://google.com")
and if you not wait for complete task you can use asyncio for more information about asyncio read this article如果您不等待完成任务,您可以使用 asyncio 了解有关 asyncio 的更多信息,请阅读本文
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.