当我使用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
答案 0 :(得分:2)
使用清单:
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)