分裂 .type() 文本然后变量

Splinter .type() text then variable

我正在尝试将 splinter 用作浏览器游戏中的机器人。
这是我的主要代码块

lastMess = ""
mainMess = ""
userName = ""
bailOut = 0
intCommand = "/whoami"
while bailOut == 0:
    if browser.find_by_css('.chatMessage-main').first.text != lastMess:
        lastMess = browser.find_by_css('.chatMessage-main').first.text
        mainMess = browser.find_by_css('.chatMessage-main').first
        userName = mainMess.find_by_css('.chatMessage-text').first.text
        print(browser.find_by_css('.chatMessage-main').first.text)
        print(mainMess.find_by_css('.chatMessage-message').text)
        if intCommand == mainMess.find_by_css('.chatMessage-message').text:
            browser.find_by_id('chat_input').type("You are ",userName)
            print(browser.find_by_id('chat_input').type("You are ",userName))
            browser.find_by_id('chat_submit').click()
            print("Reply Sent")

如果我这样做就可以正常工作

browser.find_by_id('chat_input').type("You are")

browser.find_by_id('chat_input').type(userName)

但如果他们在一起就不会

browser.find_by_id('chat_input').type("You are ",userName)

有办法吗?

当我输入这个时,我想出了一个答案

if intCommand == mainMess.find_by_css('.chatMessage-message').text:
    browser.find_by_id('chat_input').type("You are ")
    browser.find_by_id('chat_input').type(userName)
    browser.find_by_id('chat_submit').click()
    print("Reply Sent")

如果我只做两条不同的线就可以了。它可能不是最有效的,但它完成了工作