Python在另一个函数

时间:2017-08-05 22:54:10

标签: python function selenium

这是我的代码: 在函数add_new_employee中我得到employee_id然后我想在我的下一个函数employee_id中使用new_employee_added 有人可以帮助我吗?谢谢

employee_id= ()
def add_new_employee(driver, first_name, last_name):
    driver.find_element_by_css_selector("#menu_pim_viewPimModule").click()
    driver.find_element_by_css_selector("[name='btnAdd']").click()
    driver.find_element_by_css_selector("#firstName").send_keys(first_name)
    driver.find_element_by_css_selector("#lastName").send_keys(last_name)
    driver.find_element_by_css_selector("#photofile").\
        send_keys(os.path.abspath("cloud-computing-IT.jpg"))
    global employee_id
    employee_id = 
   driver.find_element_by_css_selector("#employeeId").get_attribute("value")
    return employee_id

def new_employee_added(driver):
    global employee_id
    driver.find_element_by_css_selector("#menu_pim_viewPimModule").click()
    for i in range(1, 50):
        try:
            driver.find_element_by_link_text("%s" % employee_id).click()
            break
        except NoSuchElementException:
            driver.find_element_by_link_text("%s" % i).click()

def test_new_employee(driver, first_name="Patrick", last_name="Patterson"):
    login(driver, username="Admin", password="Password")
    # add new user with First Name, Last Name and Photo
    add_new_employee(driver,first_name, last_name)
    #verify that new employee added
    new_employee_added(driver)
    #ckeck if we got the right employee page
    logout(driver)

在函数add_new_employee中我得到employee_id然后我想在我的下一个函数employee_id中使用new_employee_added 有人可以帮助我吗?谢谢

2 个答案:

答案 0 :(得分:1)

将参数添加到函数定义中,然后在调用它时将其传入:

{{1}}

答案 1 :(得分:0)

只需将add_new_employee的输出保存在局部变量中,然后将其作为参数传递给new_employee_added函数。