Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix regression introduced by 5c4833e. Closes: #140 #141

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions alright/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import sys
import time
import logging
import platformdirs
from typing import Optional
from pathlib import Path
from selenium import webdriver
Expand All @@ -28,13 +29,13 @@


class WhatsApp(object):
def __init__(self, browser=None, time_out=600):
def __init__(self, headless=False, browser=None, time_out=600):
# CJM - 20220419: Added time_out=600 to allow the call with less than 600 sec timeout
# web.open(f"https://web.whatsapp.com/send?phone={phone_no}&text={quote(message)}")

self.BASE_URL = "https://web.whatsapp.com/"
self.suffix_link = "https://web.whatsapp.com/send?phone={mobile}&text&type=phone_number&app_absent=1"

self.headless= headless
if not browser:
browser = webdriver.Chrome(
ChromeDriverManager().install(),
Expand All @@ -57,12 +58,14 @@ def __init__(self, browser=None, time_out=600):
@property
def chrome_options(self):
chrome_options = Options()
chrome_options.headless = self.headless
chrome_options.add_argument(
"--user-data-dir=" + platformdirs.user_data_dir("alright")
)
if sys.platform == "win32":
chrome_options.add_argument("--profile-directory=Default")
chrome_options.add_argument("--user-data-dir=C:/Temp/ChromeProfile")
else:
chrome_options.add_argument("start-maximized")
chrome_options.add_argument("--user-data-dir=./User_Data")
return chrome_options

def cli(self):
Expand Down Expand Up @@ -264,7 +267,7 @@ def search_chat_by_name(self, query: str):
search_box.send_keys(Keys.ARROW_DOWN)
chat = self.browser.switch_to.active_element

# excepcitonally acceptable here!
# acceptable here as an exception!
time.sleep(1)
flag = False
prev_name = ""
Expand Down Expand Up @@ -424,7 +427,7 @@ def send_message1(self, mobile: str, message: str) -> str:
)
# Iterate through the list of elements to test each if they are a textBox or a Button
for i in ctrl_element:
if i.aria_role == "textbox":
if i.get_attribute("role") == "textbox":
# This is a WhatsApp Number -> Send Message

for line in message.split("\n"):
Expand All @@ -438,7 +441,7 @@ def send_message1(self, mobile: str, message: str) -> str:
# Found alert issues when we send messages too fast, so I called the below line to catch any alerts
self.catch_alert()

elif i.aria_role == "button":
elif i.get_attribute("role") == "button":
# Did not find the Message Text box
# BUT we possibly found the XPath of the error "Phone number shared via url is invalid."
if i.text == "OK":
Expand Down