使用 selenium 在多个浏览器上同时运行 python SCRIPT [英] Run python SCRIPT on multiple browsers at the same time using selenium

查看:47
本文介绍了使用 selenium 在多个浏览器上同时运行 python SCRIPT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 selenium 在多个浏览器上运行我的脚本.到目前为止,我可以通过一次打开一个浏览器来执行操作.例如:- 注册到亚马逊.我希望能够同时向亚马逊注册两个用户.

I would like to run my script on Multiple browser using selenium. As of now I am able to perform the operation by opening one browser at a time. Eg:- Register to amazon. I want to be able to Register two users to amazon at the same time.

这是我目前拥有的代码.

This is the code I have as of now.

import time
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.select import Select
driver.get("https://www.amazon.com/ap/register?openid.pape.max_auth_age=0&openid.return_to=https%3A%2F%2Fwww.amazon.com%2F%3Fref_%3Dnav_signin&prevRID=VBHFJ50CPKFJ3PGG7RDY&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.assoc_handle=usflex&openid.mode=checkid_setup&openid.ns.pape=http%3A%2F%2Fspecs.openid.net%2Fextensions%2Fpape%2F1.0&prepopulatedLoginId=&failedSignInCount=0&openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&pageId=usflex&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0")
            driver.find_element_by_xpath("""//*[@id="s2id_ID_form4a8055de_guest_register_sponsor_lookup"]/a/span[2]/b""").click()
            driver.find_element_by_xpath("""//*[@id="s2id_autogen1_search"]""").send_keys(v1)

通过使用它,我可以一次为一个用户运行它.但我希望能够同时注册两个以上的用户,最多 n 个用户.因此,多窗口问题.

By using this I can run it for one user at one time. But I want to be able to register more than two users upto n users at the same time. Hence, the multiple windows questions.

推荐答案

您可以创建 webdriver 的多个实例.然后您可以单独操作每个.例如,

You could create multiple instances of the webdriver. You can then manipulate each individually. For example,

from selenium import webdriver
driver1 = webdriver.Chrome()
driver2 = webdriver.Chrome()
driver1.get("http://google.com")
driver2.get("http://yahoo.com")

这篇关于使用 selenium 在多个浏览器上同时运行 python SCRIPT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆