Python selenium issue - Message: chrome not reachable

Viewed 34

I had an issue when I sent message WhatsApp with selenium, opened chat but did not send message and showed error chrome not reachable. I installed latest version with google chrome , chrome drive and selenium and installed selenium binary How to solve this issue?

   from selenium import webdriver
   from selenium.webdriver.chrome.service import Service
   from selenium.webdriver.chrome.options import Options
   from selenium.common.exceptions import WebDriverException
   from webdriver_manager.chrome import ChromeDriverManager
   from selenium.webdriver.support.ui import WebDriverWait
   from selenium.webdriver.support import expected_conditions as EC
   from selenium.webdriver.common.keys import Keys
   from selenium.webdriver.common.by import By
   import time
   import re

   app_path=sys.path[0].split('\\')
   #del app_path[-1]
   final_path=''
   for i in app_path:
      final_path=final_path+i+'\\'
   try:
      os.mkdir(final_path+'whatsapp_data')
   except:
        pass

   new_text=[]
   new_email=[]

   def send_func():
        s=Service(ChromeDriverManager().install())
        options=Options()
        options.add_argument('--user-data-dir='+final_path+'whatsapp_data')
        options.add_experimental_option('excludeSwitches',['enable-automation'])
        options.add_experimental_option('useAutomationExtension',False)
        options.add_argument('--incognitos')
        options.add_argument('start-maximized')
        options.add_argument('--no-sandbox')
        driver = webdriver.Chrome(service=s,options=options)
        driver.get("https://web.whatsapp.com/")
        wait = WebDriverWait(driver, 800)
        
        for phone_number in number_listbox.get('1.0','end').replace(' ','').split(','):
            driver.get("https://web.whatsapp.com/send?phone={}".format(phone_number))
            try:
                driver.switch_to.alert.accept()
            except:
                pass
            string = message_entry.get('1.0','end')
            inp_xpath = '//div[@class="_13NKt copyable-text selectable-text"][@data-tab="10"]'
            input_box = wait.until(EC.presence_of_element_located((
                By.XPATH, inp_xpath)))
            input_box.click()
            input_box.send_keys(string + Keys.ENTER)
            
            attachment_box = driver.find_element(By.XPATH,'//div[@title = "Attach"]')
            attachment_box.click()
            image_box = driver.find_element(By.XPATH,'//input[@accept="image/*,video/mp4,video/3gpp,video/quicktime"]')
            image_box.send_keys(final_path+'db.jpg')
           
            WebDriverWait(driver,1).until(EC.element_to_be_clickable((By.XPATH,'//span[@data-icon="send"]'))).click()
            time.sleep(int(delay_entry.get()))
0 Answers
Related