簡體   English   中英

我如何在其他功能中使用第一個功能的結果

[英]How I can use result of first function in other function

我想將psw變量==>放在def test_1 / .send_keys()中

def random_list():
    psw = ''
    for x in range(12):
        psw = psw + random.choice(list('123456789qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM'))
    return psw


def test_1(driver):
    driver.find_element_by_xpath("//form//a").click()
    driver.find_element_by_xpath("//input[@name='tax_id']").send_keys(random_list)

您需要調用該函數。 所以driver.find_element_by_xpath(“ // input [@ name ='tax_id']”)。send‌_keys(random_list())– Yevhen Kuzmovych

簡單的方法:

def random_list():
    psw = ''
    for x in range(12):
        psw = psw + random.choice(list('123456789qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM'))
    return psw


def test_1(driver):
    driver.find_element_by_xpath("//form//a").click()
    new_random=random_list()
    driver.find_element_by_xpath("//input[@name='tax_id']").send_keys(new_random)

全部一起:

def random_list():
    psw = ''
    for x in range(12):
        psw = psw + random.choice(list('123456789qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM'))
    return psw


def test_1(driver):
    driver.find_element_by_xpath("//form//a").click()
    driver.find_element_by_xpath("//input[@name='tax_id']").send_keys(random_list())

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM