How to use press_escape method in Selene

Best Python code snippet using selene_python

utils.py

Source:utils.py Github

copy

Full Screen

...101def go_main_screen():102 old_dbg_name = const.dbg_name.__str__()103 const.dbg_name = 'escape'104 save_print_dbg("**Debug for action 'press escape'")105 [press_escape() for _ in range(3)]106 while True:107 sleep(SLEEP)108 try:109 find_image_and_click_then_sleep(110 COMMON_NO, retry_time=1, sleep_duration=0.5)111 break112 except:113 pass114 press_escape()115116 save_print_dbg("**Finished action 'press escape'")117 const.dbg_name = old_dbg_name118119120def raise_exception_when_runnable(fun, exception: Exception):121 try:122 fun()123 sleep(SLEEP)124 raise exception()125 except exception as ex:126 raise ex127 except KeyboardInterrupt as ex:128 raise ex129 except:130 pass131132133def enable_auto_on() -> bool:134 img = get_game_screen()135 try:136 find_image(COMMON_AUTO_ON, retry_time=1,137 threshold=0.9, game_screen=img)138 return True139 except:140 pass141142 try:143 y, x = find_image(COMMON_AUTO_OFF, retry_time=1,144 threshold=0.9, game_screen=img)145 click_screen_and_sleep(y, x)146 return True147 except:148 pass149150 return False151152153def click_town_or_rerun(is_rerun=False) -> bool:154 img = COMMON_RERUN if is_rerun else COMMON_TOWN155 try:156 y, x = find_image(img, retry_time=1, threshold=0.9)157 sleep(1)158 click_screen_and_sleep(y, x)159 return True160 except:161 return False162163164def check_no_energy(keep_guide=False):165 def find_not_energy():166 try:167 _, _, img = find_image(168 COMMON_NOT_ENOUGH, threshold=0.9, retry_time=3, return_game_screen=True)169 y, x = find_image(COMMON_NO, threshold=0.9,170 retry_time=3, game_screen=img)171 sleep(SLEEP)172 click_screen_and_sleep(y, x)173 except:174 # in case of warning can't leave guild, click yes175 if keep_guide:176 find_image_and_click_then_sleep(177 COMMON_YES, threshold=0.9, retry_time=3)178 raise Exception()179180 sleep(SLEEP)181 raise_exception_when_runnable(182 lambda: find_not_energy(),183 NoEnergyException184 )185186187def click_cost_and_play(cost: str, menu_cost=COMMON_COST, play_btn=COMMON_PLAY, keep_guide=False):188 select_cost(cost=cost, menu_cost=menu_cost)189 click_play_and_check_no_energy(play_btn=play_btn, keep_guide=keep_guide)190191192def select_cost(cost: str, menu_cost=COMMON_COST):193 find_image_and_click_then_sleep(menu_cost, retry_time=5)194 clicked = False195 try:196 find_image_and_click_then_sleep(197 cost, retry_time=3, sleep_duration=0.5, threshold=0.9)198 clicked = True199 find_image(cost, retry_time=1)200 press_escape()201 except:202 if not clicked:203 press_escape()204 finally:205 sleep(SLEEP)206207208def click_play_and_check_no_energy(play_btn=COMMON_PLAY, keep_guide=False):209 find_image_and_click_then_sleep(play_btn, retry_time=5, sleep_duration=1)210 check_no_energy(keep_guide=keep_guide)211 check_not_full_team()212213214def check_not_full_team():215 def _run():216 find_image(COMMON_TEAM_NOT_FULL, retry_time=2)217 find_image_and_click_then_sleep(218 COMMON_NO, retry_time=2, ignore_exception=True)219 raise_exception_when_runnable(_run, NotFullTeamException)220221222def fight_wait_town(is_rerun=False):223 sleep(1)224 while not enable_auto_on():225 sleep(SLEEP)226 while not click_town_or_rerun(is_rerun=is_rerun):227 sleep(1)228229230def decline_except_persuade(decline):231 y, x, img = None, None, None232 try:233 y, x, img = find_image(decline, retry_time=1, return_game_screen=True)234 find_image(COMMON_PERSUADE, retry_time=1, game_screen=img)235 except:236 if y != None:237 click_screen_and_sleep(y, x, sleep_duration=0.5)238 find_image_and_click_then_sleep(239 COMMON_YES, retry_time=1, ignore_exception=True)240241242def open_treasure():243 try:244 find_image_and_click_then_sleep(245 COMMON_OPEN, retry_time=1, sleep_duration=0.5)246 find_image_and_click_then_sleep(247 COMMON_YES, retry_time=1, sleep_duration=0.5)248 # decline when no key249 find_image_and_click_then_sleep(250 COMMON_NO, retry_time=1, sleep_duration=0.5)251 press_escape()252 sleep(SLEEP)253 find_image_and_click_then_sleep(254 COMMON_YES, retry_time=1, sleep_duration=0.5)255 except:256 pass257258259def get_json_file(file) -> dict:260 with open(file, 'r') as f:261 return json.load(f)262263264def save_json_file(file, data, is_sort=False) -> dict:265 with open(file, 'w') as f: ...

Full Screen

Full Screen

whatsappbotsetting.py

Source:whatsappbotsetting.py Github

copy

Full Screen

...11 """ Returns th chosen element from the sub menue - This function must be called after settings is called 12 choice is in ['New group', 'Profile', 'Archived', 'Starred', 'Settings', 'Log out'] """13 self.settings['menu'].click()14 return self.bot.driver.find_element_by_xpath(f"//*[contains(text(), '{choice}')]")15 def press_escape(self):16 webdriver.ActionChains(self.bot.driver).send_keys(Keys.ESCAPE).perform()17class WhatsappBotGeneralSettings(WhatsappBotSettingsBase):18 def settings(self):19 self.settings = {'status': self.bot.driver.find_element_by_xpath("//*[contains(@title, 'Status')]"),20 'new_chat': self.bot.driver.find_element_by_xpath("//*[contains(@title, 'New chat')]")}21 self.settings['menu'] = self.settings['new_chat'].find_element_by_xpath("../following-sibling::div")22 def write_in_search(self, query):23 """ Types query to the general search box """24 self.bot.driver.find_element_by_xpath("//*[contains(text(), 'Search or start new chat')]/..").click()25 actions = ActionChains(self.bot.driver)26 actions.send_keys(query)27 actions.perform()28 def close_search(self):29 """ Closes the search box """30 self.press_escape()31 def click_on_first_result(self):32 """ Clicks on the first conversation """33 self.bot.driver.find_element_by_xpath("//*[contains(text(), 'Chats')]").click()34class WhatsappBotConversationSettings(WhatsappBotSettingsBase):35 def settings(self):36 self.settings = {'search': self.bot.driver.find_element_by_xpath("//*[contains(@title, 'Search')]"),37 'attach': self.bot.driver.find_element_by_xpath("//*[contains(@title, 'Attach')]")}38 self.settings['menu'] = self.settings['attach'].find_element_by_xpath("../following-sibling::div")39 self.settings['title'] = self.settings['search'].find_element_by_xpath(...

Full Screen

Full Screen

find_tweets.py

Source:find_tweets.py Github

copy

Full Screen

...18 press_enter(actions, 0.2)19 press_tab(actions, 0.2)20 press_enter(actions, 0.2)21 tweets.append(f"{paste()}\n")22 press_escape(actions, 0.2)23 24 if len(tweets) >= number:25 break26 finally:27 with open("_tweets.txt", "a") as f:...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Selene automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful