如何在其他功能中使用第一个功能的结果

时间:2016-12-06 22:59:32

标签: python function selenium

我想放置psw变量==>在def test_1 / .send_keys()

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

    <div id="DTE" style="position: fixed; height:15px; font-size:70%; border-radius: 3px; background-color:lightcyan; text-align:center; width:11.8%; margin-left:34.55%; color:black"></div>
 
    <div class="date" date="02 Dec 2016" style="height:15px; font-size:70%; background-color:#2E64FE; text-align:center; width:15%; margin-left:44%; color:white">02 Dec 2016</div>
    <p style="height: 100px; margin-left: 44%">Text related to 02 Dec 2016</p> 
    <br/>
    <p style="height: 50px; margin-left: 44%">More text related to 02 Dec 2016</p>
    <br/>
    <div class="date" date="03 Dec 2016" style="height:15px; font-size:70%; background-color:#2E64FE; text-align:center; width:15%; margin-left:44%; color:white">03 Dec 2016</div>
    <p style="height: 100px; margin-left: 44%">Text related to 03 Dec 2016</p> 
    <br/>
    <p style="height: 50px; margin-left: 44%">More text related to 03 Dec 2016</p>
    <br/> 
    <div class="date" date="04 Dec 2016" style="height:15px; font-size:70%; background-color:#2E64FE; text-align:center; width:15%; margin-left:44%; color:white">04 Dec 2016</div>
    <p style="height: 100px; margin-left: 44%">Text related to 04 Dec 2016</p> 
    <br/>
    <p style="height: 50px; margin-left: 44%">More text related to 04 Dec 2016</p>
    <br/>   
    <div class="date" date="05 Dec 2016" style="height:15px; font-size:70%; background-color:#2E64FE; text-align:center; width:15%; margin-left:44%; color:white">05 Dec 2016</div>
    <p style="height: 100px; margin-left: 44%">Text related to 05 Dec 2016</p> 
    <br/>
    <p style="height: 500px; margin-left: 44%">More text related to 05 Dec 2016</p> 
    <br/>

2 个答案:

答案 0 :(得分:0)

您需要调用该函数。所以driver.find_element_by_xpath(&#34; //输入[@name =&#39; tax_id&#39;]&#34;)。发送_keys(random_list()) - Yevhen Kuzmovych

答案 1 :(得分:0)

简单方法:

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)

All Together:

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())