Kalebu / alright

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

Cannot send message with picture #143

Open dhmyess opened 10 months ago

dhmyess commented 10 months ago

Help,

I cant send picture, when using messenger.send_picture('image.jpg', "test sending image") it just stuck on image, no text added and not send

when i try send message without images get error like these messenger.send_message("test")

2023-11-30 17:19:55,973 - root -- [INFO] >> Message sent successfuly to 2023-11-30 17:19:55,973 - WDM -- [INFO] >> ====== WebDriver manager ====== 2023-11-30 17:19:56,036 - WDM -- [INFO] >> Get LATEST chromedriver version for google-chrome 2023-11-30 17:19:56,182 - WDM -- [INFO] >> Get LATEST chromedriver version for google-chrome 2023-11-30 17:19:56,279 - WDM -- [INFO] >> Driver [/home/dharma/.wdm/drivers/chromedriver/linux64/119.0.6045.105/chromedriver-linux64/chromedriver] found in cache Traceback (most recent call last): File "/home/dharma/Unduhan/ktp/halid/baru/wa.py", line 8, in messenger = WhatsApp() # Inisialisasi objek WhatsApp di luar fungsi ^^^^^^^^^^ File "/home/dharma/.local/lib/python3.11/site-packages/alright/init.py", line 39, in init browser = webdriver.Chrome( ^^^^^^^^^^^^^^^^^ File "/home/dharma/.local/lib/python3.11/site-packages/selenium/webdriver/chrome/webdriver.py", line 70, in init super(WebDriver, self).init(DesiredCapabilities.CHROME['browserName'], "goog", File "/home/dharma/.local/lib/python3.11/site-packages/selenium/webdriver/chromium/webdriver.py", line 92, in init RemoteWebDriver.init( File "/home/dharma/.local/lib/python3.11/site-packages/selenium/webdriver/remote/webdriver.py", line 275, in init self.start_session(capabilities, browser_profile) File "/home/dharma/.local/lib/python3.11/site-packages/selenium/webdriver/remote/webdriver.py", line 365, in start_session response = self.execute(Command.NEW_SESSION, parameters) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/dharma/.local/lib/python3.11/site-packages/selenium/webdriver/remote/webdriver.py", line 430, in execute self.error_handler.check_response(response) File "/home/dharma/.local/lib/python3.11/site-packages/selenium/webdriver/remote/errorhandler.py", line 247, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.SessionNotCreatedException: Message: session not created: Chrome failed to start: exited normally. (session not created: DevToolsActivePort file doesn't exist) (The process started from chrome location /opt/google/chrome/chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.) Stacktrace:

0 0x55e6df3ae5e3

1 0x55e6df0710b7

2 0x55e6df0a7e55

3 0x55e6df0a4b81

4 0x55e6df0ef47f

5 0x55e6df0e5cc3

6 0x55e6df0b10e4

7 0x55e6df0b20ae

8 0x55e6df374ce1

9 0x55e6df378b7e

10 0x55e6df3624b5

11 0x55e6df3797d6

12 0x55e6df345dbf

13 0x55e6df39c748

14 0x55e6df39c917

15 0x55e6df3ad773

16 0x7f95e9c15044

dhmyess commented 9 months ago

xpath changes sometimes between 2 xpath //[@id="app"]/div/div[2]/div[2]/div[2]/span/div/span/div/div/div[2]/div/div[1]/div[3]/div/div/div[2]/div[1]/div[1]/p or //[@id="app"]/div/div[2]/div[2]/div[2]/span/div/span/div/div/div[2]/div/div[1]/div[3]/div/div/div/div[1]/div[1]/p

on xpath_map

def add_caption(self, message: str, media_type: str = "image"):
    xpath_map = {
        "image": "/html/body/div[1]/div/div/div[3]/div[2]/span/div/span/div/div/div[2]/div/div[1]/div[3]/div/div/div[2]/div[1]/div[1]",
        "video": "/html/body/div[1]/div/div/div[3]/div[2]/span/div/span/div/div/div[2]/div/div[1]/div[3]/div/div/div[1]/div[1]",
        "file": "/html/body/div[1]/div/div/div[3]/div[2]/span/div/span/div/div/div[2]/div/div[1]/div[3]/div/div/div[1]/div[1]",
    }