Skip to content

Commit

Permalink
send multiple lines #34 + bug #43 (#47)
Browse files Browse the repository at this point in the history
* send multiple lines #34 + bug #43

Allowing __type_slow__ to send a single message with newlines #34
Fixing function call never received 'element' and 'element' overwritten in function #43

* allow last char \n to submit the message
  • Loading branch information
amastis authored Jul 27, 2022
1 parent ae181ac commit 2f4e22a
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions instadm.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def typeMessage(self, user, message):
self.__random_sleep__()

if self.__wait_for_element__(self.selectors['send'], "xpath"):
self.__remove_browser_unsupported_banner_if_exists(self, element):
self.__remove_browser_unsupported_banner_if_exists()
self.__get_element__(self.selectors['send'], "xpath").click()
self.__random_sleep__(3, 5)
print('Message sent successfully')
Expand Down Expand Up @@ -326,8 +326,12 @@ def __type_slow__(self, element_tag, locator, input_text=''):
element = self.__get_element__(element_tag, locator)
actions = ActionChains(self.driver)
actions.click(element).perform()
for s in input_text:
element.send_keys(s)
for index, s in enumerate(input_text):
# https://stackoverflow.com/questions/53901388/how-do-i-manipulate-shiftenter-instead-of-n/53909017#53909017
if s == '\n' and index != len(input_text) - 1:
element.send_keys(Keys.SHIFT, s)
else:
element.send_keys(s)
sleep(uniform(0.25, 0.75))

except Exception as e:
Expand All @@ -346,7 +350,7 @@ def teardown(self):
self.driver.close()
self.driver.quit()

def __remove_browser_unsupported_banner_if_exists(self, element):
def __remove_browser_unsupported_banner_if_exists(self):
element = self.__get_element__('rh7Wz', 'CLASS')
if element is not None:
self.driver.execute_script("""
Expand Down

0 comments on commit 2f4e22a

Please sign in to comment.