如何在driver.get()中加载多个URL?

问题描述 投票:0回答:2

如何在driver.get()中加载多个URL?

我正在尝试在下面的代码中加载3个URL,但是如何加载其他2个URL?

然后,下一个挑战是对所有相同的URL都通过身份验证。

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

driver = webdriver.Chrome(executable_path=r"C:/Users/RYadav/AppData/Roaming/Microsoft/Windows/Start Menu/Programs/Python 3.8/chromedriver.exe")

driver.get("https://fleet.my.salesforce.com/reportbuilder/reportType.apexp")#put here the adress of your page

elem = driver.find_elements_by_xpath('//*[@id="ext-gen63"]')#put here the content you have put in Notepad, ie the XPath

button = driver.find_element_by_id('id="ext-gen63"')

print(elem.get_attribute("class"))

driver.close

submit_button.click()
python selenium url driver multiple
2个回答
0
投票

每个Webdriver一次最多只能加载1个网址。如果要这样做,可能需要一些多处理模块。如果要执行迭代解决方案,只需创建一个列表,其中包含所需的每个URL并循环遍历。这样,您也不会遇到证书问题。


0
投票

尝试下面的代码:

def getUrls(targeturl):
    driver = webdriver.Chrome(executable_path=r" path for chromedriver.exe")
    driver.get("http://www."+targeturl+".com")
    # perform your taks here
    driver.quit()

for i in range(3):
    webPage = ['google','facebook','gmail']
    for i in webPage:
        print i;
        getUrls(i)
© www.soinside.com 2019 - 2024. All rights reserved.