I am using send_keys command without using key_up, and I am inclined to think that upon calling ActionChains.reset_actions() the keys that I was send_keying should be released, but alas, they are not.
I tried using key_up, but it is only for modifiers, so it did not help.
EDIT: Creating new ActionChains object each time process() is called did the trick, but I still expected reset_actions to do the same.
import os
import time
import selenium
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
my_path = os.path.dirname(os.path.abspath(__file__))
driver_path = my_path + "//chromedriver.exe"
bot_wakeword = "BOT"
class Bot:
def __init__(self):
# Using Chrome as our browser.
self.driver = webdriver.Chrome(driver_path)
# Open Gridworlds.
self.driver.get('*my url here')
# Waiting till our page loads.
WebDriverWait(self.driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.TAG_NAME,"frame")))
# Finding a div rps-wrapper with events in it. The events element is our chat.
self.chat = WebDriverWait(self.driver, 10).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "div.rps-wrapper>ul#events")))
# So we surely are on the page.
self.chat.click()
self.actions = ActionChains(self.driver)
def get_last_message(self):
messages = self.chat.find_elements_by_tag_name("li")
return messages[len(messages) - 1].get_attribute("innerHTML")
def parse_command_from_message(self, message):
wake_word = message.find(bot_wakeword)
if(wake_word >= 0):
if(message.find("up") >= 0):
self.actions.send_keys(Keys.ARROW_UP)
elif(message.find("right") >= 0):
self.actions.send_keys(Keys.ARROW_RIGHT)
elif(message.find("down") >= 0):
self.actions.send_keys(Keys.ARROW_DOWN)
elif(message.find("left") >= 0):
self.actions.send_keys(Keys.ARROW_LEFT)
def process(self):
self.actions.reset_actions()
self.parse_command_from_message(self.get_last_message())
self.actions.perform()
bots = []
for i in range(1):
bots.append(Bot())
while(True):
for bot in bots:
bot.process()```
I expected reset_actions to release all keys that I previously send_keyed, but it did not release them.