-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmessenger.py
More file actions
79 lines (63 loc) · 2.65 KB
/
messenger.py
File metadata and controls
79 lines (63 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
from appium import webdriver
from appium.webdriver.common.touch_action import TouchAction
import time
yourMessage = ""
yourUserName = ""
yourPassword = ""
class driver:
def __init__(self, webdriver):
self.webdriver = webdriver
self.action = TouchAction(webdriver)
def log_in(dr):
login = dr.webdriver.find_element_by_id("com.instagram.android:id/log_in_button")
dr.action.tap(login).perform()
username = dr.webdriver.find_element_by_id("com.instagram.android:id/login_username")
dr.webdriver.set_value(username, yourUserName)
password = dr.webdriver.find_element_by_id("com.instagram.android:id/login_password")
dr.webdriver.set_value(password, yourPassword)
login = dr.webdriver.find_element_by_id("com.instagram.android:id/next_button")
dr.action.tap(login).perform()
def open_messages_tab(dr):
inbox = dr.webdriver.find_element_by_id("com.instagram.android:id/action_bar_inbox_icon_with_badge")
dr.action.tap(inbox).perform()
def send_message(dr):
writeField = dr.webdriver.find_element_by_id("com.instagram.android:id/row_thread_composer_edittext")
writeField.send_keys(yourMessage)
sendButton = dr.webdriver.find_element_by_id("com.instagram.android:id/row_thread_composer_button_send")
dr.action.tap(sendButton).perform()
backButton = dr.webdriver.find_element_by_id("com.instagram.android:id/action_bar_button_back")
dr.action.tap(backButton).perform()
def respond_to_users(dr):
messages = dr.webdriver.find_elements_by_id("com.instagram.android:id/row_inbox_digest")
for message in messages:
if message.get_attribute('text') != yourMessage:
dr.action.tap(message).perform()
send_message(dr)
break
""" desired_caps are desired Capabilities, they are like prefrences for your virtual machine,
learn more about what you can use at:
https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/caps.md """
desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '7.1.1'
desired_caps['deviceName'] = 'Android Simulator'
desired_caps['appActivity'] = '.activity.MainTabActivity'
desired_caps['appPackage'] = 'com.instagram.android'
# desired_caps['newCommandTimeout'] = 0 # needed only for testing purposes, leave commented
try:
dr = driver(webdriver.Remote('http://localhost:4723/wd/hub', desired_caps))
print("Session started with id: " + str(dr.webdriver.session_id)) # the session id can be usefull if you
# want to attach to the session from appium-desktop
log_in(dr)
open_messages_tab(dr)
while True:
respond_to_users(dr)
time.sleep(2)
except:
import traceback
import sys
e = sys.exc_info()
print("Error: %s , %s " % (e[0], e[1]))
traceback.print_tb(e[2])
dr.webdriver.quit()
sys.exit()