【发布时间】:2020-06-18 07:28:48
【问题描述】:
from selenium import webdriver
import time
def test_setup():
global driver
driver = webdriver.Chrome(executable_path="C:/ChromeDriver/chromedriver.exe")
driver.implicitly_wait(5)
driver.maximize_window()
time.sleep(5)
siteUrls = ["https://www.espncricinfo.com/", "https://www.t20worldcup.com/","https://www.iplt20.com/"]
for url in siteUrls:
openSite(url)
def openSite(siteUrl):
driver.get(siteUrl)
time.sleep(5)
print("ESPN website is launched successfully")
def test_teardown():
driver.close()
driver.quit()
上面是我的代码,它运行得非常好,我的问题是它打印与所有 3 个 URL 的输出相同的语句,但我希望它打印 3 个不同的语句
例如 - 我想要下面的预期输出
ESPN website is launched successfully
IPL website is launched successfully
world-cup site is launched successfully
But, currently I get output as below ( same statement repeated 3 times)
ESPN website is launched successfully
ESPN website is launched successfully
ESPN website is launched successfully
【问题讨论】:
-
您的打印语句中没有任何参数。
-
print(siteUrl + " is launched successfully")或print(f"{siteUrl} is launched successfully")怎么样
标签: python selenium loops printing