Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Chat bot
#11
(Dec-12-2019, 01:59 AM)ichabod801 Wrote: Make a version of that function with no try/except blocks, and post the full error message you get.
I already provided such version, yet they don't run it
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#12
@akanowhere, you have to print the global exceptions that you are catching to see the actual error.

So, please change line # 32,33 as
 except Exception as e:
    print(e) 
Line #43, 44
 except Exception as e1:
     print(e1)
Similarly print the exception in line #48, 49. By looking at the actual exception only we can dig it further
Reply
#13
Exclamation 
Hi again...tks for you help....so I removed all try an exceptions and re run.....so
here below the results....


from time import sleep
from selenium.webdriver.common.by import By
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait
import socket
#import csv
    
message_text='Ola essa é uma mensagem automatizada de Whats App.' # message
no_of_message = 1 # no. of time
moblie_no_list = [5551981440050, 5551982073305] # list of phone number
#moblie_no_list= open('entrada.csv', 'r')
    
def element_presence(by,xpath,time):
    element_present = EC.presence_of_element_located((By.XPATH, xpath))
    WebDriverWait(driver, time).until(element_present)
    
 
  
driver = webdriver.Chrome(executable_path="D:\Programas\Aulas\scripts\Projetos\whatsautomatico\chromedriver.exe")
driver.get("http://web.whatsapp.com")
sleep(10) #wait time to scan the code in second
    
def send_whatsapp_msg(phone_no,text):
    driver.get("https://web.whatsapp.com/send?phone={}&source=&data=#".format(phone_no))
    try:
          
        #driver.switch_to_alert.accept()
        driver.switch_to_alert().accept()
    except Exception as e1:
        print(e1)
    
    try:
        element_presence(By.XPATH,'//*[@id="main"]/footer/div[1]/div[2]/div/div[2]',30)
        txt_box=driver.find_element(By.XPATH , '//*[@id="main"]/footer/div[1]/div[2]/div/div[2]')
        global no_of_message
        for x in range(no_of_message):
            txt_box.send_keys(text)
            txt_box.send_keys("\n")
        
    except Exception as e:
         print("invailid phone no :"+str(phone_no))
for moblie_no in moblie_no_list:
    try:
        send_whatsapp_msg(moblie_no, message_text)
    except Exception as e:
            print (sleep(10))
Output:
DevTools listening on ws://127.0.0.1:50930/devtools/browser/c9c10590-5205-4764-8bf8-6d1cbcb2b581
Error:
Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:04:45) [MSC v.1900 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. >>> == RESTART: D:\Programas\Aulas\scripts\Projetos\whatsautomatico\Aut0001.py == 'WebDriver' object has no attribute 'switch_to_alert' 'WebDriver' object has no attribute 'switch_to_alert' invailid phone no :5551982073305 >>> == RESTART: D:\Programas\Aulas\scripts\Projetos\whatsautomatico\Aut0001.py == 'WebDriver' object has no attribute 'switch_to_alert' 'WebDriver' object has no attribute 'switch_to_alert' invailid phone no :5551982073305
Reply
#14
line 44!!!! you still print your msg, not the error
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#15
line 44 print: is this ?????(+str(phone_no))

Error:
= RESTART: D:\Programas\Aulas\scripts\Projetos\whatsautomatico\Aut0001.py == 'WebDriver' object has no attribute 'switch_to_alert' 'WebDriver' object has no attribute 'switch_to_alert' None >>>
Reply
#16
Now you see what the error is. Also, if you were runing my suggested code you would see the whole traceback, now you print just the message. Still it's better than your custom message which was misleading

try to replace
driver.switch_to_alert().accept()
with
driver.switch_to.alert.accept()
or

Alert(driver).accept()
reading
https://selenium-python.readthedocs.io/a...mmon.alert
https://selenium-python.readthedocs.io/a...h_to_alert
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#17
I LOVE YOU MAN!!!!!!!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question download watsapp chat Orliv 1 1,751 Jan-26-2021, 07:01 PM
Last Post: Larz60+
  I am trying to send message in youtube live chat stylohunk 1 2,574 Jun-08-2019, 04:06 PM
Last Post: SheeppOSU
Sad Twitch Chat Bot - Disconnects after 10 minutes sp4wny 0 3,885 Dec-20-2017, 08:28 AM
Last Post: sp4wny
  Host and port problems for UDP chat server YevesDraco 2 3,799 May-07-2017, 04:35 PM
Last Post: YevesDraco
  How to use a UDP server and client to setup a chat abrew132 2 3,748 Mar-20-2017, 06:22 PM
Last Post: abrew132
  Scraping Content from Google Chat ATXpython 2 5,385 Oct-26-2016, 06:07 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020