Kalebu / alright

Python wrapper for WhatsApp web-based on selenium
https://www.youtube.com/watch?v=yitQTt-NukM
MIT License
355 stars 109 forks source link

error sending message #76

Closed mohamedallam3 closed 1 year ago

mohamedallam3 commented 1 year ago

hello sir,
i install your app in my ubuntu machine , and it work , when i use class of find user it work and get the specific user, but when i send message i get exception error. message of exception is:
element not interactable

euriconicacio commented 1 year ago

Hi, @mohamedallam3 .

  1. Could you please send more details onthe error? Part of the terminal log would be nice.

  2. While that, could you try this approach, please?

messenger = WhatsApp() messenger.find_by_username("John") messenger.just_type_and_send_message("Bla\nBla\nBla") messenger.browser.quit()

Thanks a lot!

limlaw commented 1 year ago

same here, since chrome 103 or whatsapp update this everything is breaking.

I am trying the basic ones example

from alright import WhatsApp messenger = WhatsApp() messenger.find_user('2557xxxxxz') messages = ['Morning my love', 'I wish you a good night!'] for message in messages:
messenger.send_message(message)

it is able to find_user after which it just does nothing when i break the command it is waiting for something.

go_to_web = self.wait.until( File "C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\support\wait.py", line 87, in until time.sleep(self._poll)

so i try another manual send. --> messenger.send_message("Goodday")

[ERROR] >> Failed to send a message to XXXXXXXXX - Message: element not interactable (Session info: chrome=103.0.5060.134) Stacktrace: Backtrace: Ordinal0 [0x01565FD3+2187219] Ordinal0 [0x014FE6D1+1763025] Ordinal0 [0x01413D40+802112] Ordinal0 [0x0143D2F3+971507] Ordinal0 [0x0143C9D8+969176] Ordinal0 [0x0145CB8C+1100684] Ordinal0 [0x01438394+951188] Ordinal0 [0x0145CDA4+1101220] Ordinal0 [0x0146CFC2+1167298] Ordinal0 [0x0145C9A6+1100198] Ordinal0 [0x01436F80+946048] Ordinal0 [0x01437E76+949878] GetHandleVerifier [0x018090C2+2721218] GetHandleVerifier [0x017FAAF0+2662384] GetHandleVerifier [0x015F137A+526458] GetHandleVerifier [0x015F0416+522518] Ordinal0 [0x01504EAB+1789611] Ordinal0 [0x015097A8+1808296] Ordinal0 [0x01509895+1808533] Ordinal0 [0x015126C1+1844929] BaseThreadInitThunk [0x7647FE09+25] RtlGetAppContainerNamedObjectPath [0x776C662D+237] RtlGetAppContainerNamedObjectPath [0x776C65FD+189] Traceback (most recent call last): File "C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\site-packages\alright__init__.py", line 367, in send_message input_box.send_keys(line) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webelement.py", line 223, in send_keys self._execute(Command.SEND_KEYS_TO_ELEMENT, File "C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webelement.py", line 396, in _execute return self._parent.execute(command, params) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 435, in execute self.error_handler.check_response(response) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 247, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable (Session info: chrome=103.0.5060.134) Stacktrace: Backtrace: Ordinal0 [0x01565FD3+2187219] Ordinal0 [0x014FE6D1+1763025] Ordinal0 [0x01413D40+802112] Ordinal0 [0x0143D2F3+971507] Ordinal0 [0x0143C9D8+969176] Ordinal0 [0x0145CB8C+1100684] Ordinal0 [0x01438394+951188] Ordinal0 [0x0145CDA4+1101220] Ordinal0 [0x0146CFC2+1167298] Ordinal0 [0x0145C9A6+1100198] Ordinal0 [0x01436F80+946048] Ordinal0 [0x01437E76+949878] GetHandleVerifier [0x018090C2+2721218] GetHandleVerifier [0x017FAAF0+2662384] GetHandleVerifier [0x015F137A+526458] GetHandleVerifier [0x015F0416+522518] Ordinal0 [0x01504EAB+1789611] Ordinal0 [0x015097A8+1808296] Ordinal0 [0x01509895+1808533] Ordinal0 [0x015126C1+1844929] BaseThreadInitThunk [0x7647FE09+25] RtlGetAppContainerNamedObjectPath [0x776C662D+237] RtlGetAppContainerNamedObjectPath [0x776C65FD+189]

If you can test yourself see if your basic is working on chrome 103 + latest whatsapp web when performing automated messages.

euriconicacio commented 1 year ago

HI, @limlaw. Have you tried the approach I suggested above?

We'll be reviewing the usages of send_message and send_message1 shortly.

limlaw commented 1 year ago

it gives error as below

Traceback (most recent call last): File "<pyshell#1>", line 1, in wa.just_type_and_send_message("Bla\nBla\nBla") AttributeError: 'WhatsApp' object has no attribute 'just_type_and_send_message'

euriconicacio commented 1 year ago

You need to pull from main, or update your version of the __init__.py file with the current version available on this repo.

victorterancas commented 1 year ago

It happens the same to me. Whatsapp has changed the "inp_xpath" for just sending a message. Now is a dynamic route: When the textbox is empty the xpath is:

            inp_xpath = (
                '//*[@id="main"]/footer/div[1]/div/span[2]/div/div[2]/div[1]/div/div/p/br'
            )

While when I introduce something like "blabla" is:

            inp_xpath = (
                '//*[@id="main"]/footer/div[1]/div/span[2]/div/div[2]/div[1]/div/div/p/span'
            )

I send a gif to show the code:

(10) WhatsApp - Google Chrome 2022-07-26 18-04-34

I am trying to solve but i am quite new to xpath and selenium. I find this webpage that may help.

abdullahalshubaili commented 1 year ago

i was not able to send a message also, i have found a solution that worked for me. try changing the inp_xpath to '//*[@id="main"]/footer/div[1]/div/span[2]/div/div[2]/div[1]/div/div[1]'

euriconicacio commented 1 year ago

Yes, as I said before, we are facing some compatibility issues, and the usage of inp_xpath on send_message and send_message1 are on the roadmap for being updated.

@abdullahalshubaili and @victorterancas: have you tried using the workaround I implemented and suggested above before waving on the issue?

victorterancas commented 1 year ago

Sorry @euriconicacio, I am pretty new to github. I will try to find the workaround. 😄.

abdullahalshubaili commented 1 year ago

hi @euriconicacio thanks for the help, first yes i tried the new version init file in this repo but it didnt work for me and i have tried to insert '\n' in the message and still no luck. however , it was working fine last 2 weeks ago. Second, i didnt get what you mean by waving on the issue. im not very familiar with github vocab also

Kalebu commented 1 year ago

Hi guys

I have added a new method send_direct_message that works well with both saved and unsaved contacts and you can do this by using the below snippet, It does assume your number is saved by default but you can change it by changing the saved parameter.

>>> messenger.send_direct_message(mobile, message, saved=True)

It does receive the following parameters;

  1. mobile[str] - The mobile number of the user you want to send the message to
  2. message[str] - The message you want to send
  3. saved[bool] - If you want to send to a saved contact or not, default is False

Here is an example on how to use it;

>>> from alright import WhatsApp
>>> messenger = WhatsApp()
>>> >>> messenger.send_direct_message('25573652xxx', 'Hello')
2022-08-14 17:27:57,264 - root -- [INFO] >> Message sent successfuly to 
2022-08-14 17:27:57,264 - root -- [INFO] >> send_message() finished running!
>>> messenger.send_direct_message('25573652xxx', 'Who is This ?', False)
2022-08-14 17:28:30,953 - root -- [INFO] >> Message sent successfuly to 255736524388
2022-08-14 17:28:30,953 - root -- [INFO] >> send_message() finished running!