Search code examples
pythonsplinter

Splinter .type() text then variable


I am attempting to use splinter as a bot on a browser game.
This is my main code block

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

It works properly if I just do this

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

or

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

but not if they are together

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

Is there anyway to do this?


Solution

  • As I was typing this I figured out an answer

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

    If I just do two different lines it works. Its probably not the most efficient but it does the job