使用带有循环的Python创建新变量

使用带有循环的Python创建新变量,python,selenium,Python,Selenium,当我使用selenium和python运行两次时,我得到了这段代码。在运行这段代码两次之后,我想将两个不同的值保存到两个不同的变量中。例如CompanyId1和CompanyId2。这是我到目前为止尝试过的,但没有运气 driver = webdriver.Chrome() driver.maximize_window() driver.get('https://cbbb.com/') driver.find_element_by_id("email").clear() driver.find_

当我使用selenium和python运行两次时,我得到了这段代码。在运行这段代码两次之后,我想将两个不同的值保存到两个不同的变量中。例如CompanyId1和CompanyId2。这是我到目前为止尝试过的,但没有运气

driver = webdriver.Chrome()
driver.maximize_window()
driver.get('https://cbbb.com/')
driver.find_element_by_id("email").clear()
driver.find_element_by_id("email").send_keys("")
driver.find_element_by_id("login-password").clear()
driver.find_element_by_id("login-password").send_keys("")
driver.find_element_by_css_selector("input.ButtonSm").click()
driver.find_element_by_class_name('navicon_nav').click()
driver.find_element_by_link_text("Ext Contacts").click()
iframe = driver.find_element_by_id('app_win')
driver.switch_to.frame(iframe)
driver.find_element_by_css_selector("i.fa.fa-plus").click()
driver.find_element_by_name("email").clear()
driver.find_element_by_name("email").send_keys("fakefake@sake.ca")
driver.find_element_by_css_selector("input.ButtonSm").click()
driver.find_element_by_css_selector("button.ButtonSm").click()
now = datetime.datetime.now()
now = now.strftime("%Y-%m-%d %H:%M:%S")
UserName = "TestUser" + now
driver.find_element_by_name("account").send_keys(UserName)
driver.find_element_by_css_selector("input.ButtonSm").click()
driver.find_element_by_css_selector("button.ButtonSm").click()
CompanyId[i]= driver.find_element_by_xpath("//th[label[contains(text(),'CompanyId')]]/following-sibling::td").text
使用列表:

companies = []

while whatever_condition:
   # your code here
   company_id = driver.find_element_by_xpath("//th[label[contains(text(),'CompanyId')]]/following-sibling::td").text  
   companies.append(company_id)
可能重复的