Hack Forums
[Python] Python bot for whatsapp spamming. (getting error) - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [Python] Python bot for whatsapp spamming. (getting error) (/showthread.php?tid=5884087)



Python bot for whatsapp spamming. (getting error) - kookur - Sep 12, 2018

Code
from selenium import webdriver
chromedriver = "C:\\Users\\hp\\Downloads\\chromedriver_win32\\chromedriver"
driver = webdriver.Chrome(chromedriver)
driver.get("https://web.whatsapp.com/")
name = input('Enter the name of the user or group')
msg = input('Type the message here')
count = int(input('Enter the count'))

user = driver.find_elements_by_xpath('//span@title = "{}"]'.format(name))
user.click()

msg_box = driver.find_element_by_class_name('_3pkkz copyable-area')

for i in range(count):
    msg_box.send_keys(msg)
    button = driver.find_element_by_class_name('_35EW6')
    button.click()

Error i'm getting :


Code
Traceback (most recent call last):
  File "C:\Users\hp\Desktop\whatsapp.py", line 9, in <module>
    user = driver.find_elements_by_xpath('//span@title = "{}"]'.format(name))
  File "C:\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 409, in find_elements_by_xpath
    return self.find_elements(by=By.XPATH, value=xpath)
  File "C:\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 995, in find_elements
    'value': value})['value'] or []
  File "C:\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 320, in execute
    self.error_handler.check_response(response)
  File "C:\Python37\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.InvalidSelectorException: Message: invalid selector: Unable to locate an element with the xpath expression //span@title = "shyam"] because of the following error:
SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//span@title = "shyam"]' is not a valid XPath expression.
  (Session info: chrome=68.0.3440.106)
  (Driver info: chromedriver=2.41.578737 (49da6702b16031c40d63e5618de03a32ff6c197e),platform=Windows NT 10.0.17134 x86_64)

I'm very newbie to python, learning basics and learning automating stuffs at the same time so forgive this beginner !


RE: Python bot for whatsapp spamming. (getting error) - silenceMeNow - Sep 12, 2018

SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//span@title = "shyam"]' is not a valid XPath expression.


HMMMMMMM??
Maybe you should start reading your error messages. It literally stands there


RE: Python bot for whatsapp spamming. (getting error) - rybk1a - Sep 12, 2018

You should try this (Notice the forward slash after span):

Code
user = driver.find_elements_by_xpath('//span/@title = "{}"]'.format(name))



RE: Python bot for whatsapp spamming. (getting error) - kookur - Sep 12, 2018

(Sep 12, 2018 11:52 AM)rybk1a Wrote:  You should try this (Notice the forward slash after span):

Code
user = driver.find_elements_by_xpath('//span/@title = "{}"]'.format(name))

Didn't worked !


RE: Python bot for whatsapp spamming. (getting error) - mikeyymooney - Sep 13, 2018

(Sep 12, 2018 06:52 PM)kookur Wrote:  Didn't worked !

You are missing an opening bracket, try the following code below:

Code
user = driver.find_elements_by_xpath('//span[@title="{}"]'.format(name))

Notice the extra "[" before @title.


RE: Python bot for whatsapp spamming. (getting error) - kookur - Sep 13, 2018

(Sep 13, 2018 01:15 PM)mikeyymooney Wrote:  You are missing an opening bracket, try the following code below:

Code
user = driver.find_elements_by_xpath('//span[@title="{}"]'.format(name))

Notice the extra "[" before @title.

Not not worked. I was following this video :

https://www.youtube.com/watch?v=5hr0IdVM7Qg


RE: Python bot for whatsapp spamming. (getting error) - wtfrick - Sep 13, 2018

You should look into using requests instead of selenium.

PM me your Discord if you need help.


RE: Python bot for whatsapp spamming. (getting error) - kookur - Sep 13, 2018

(Sep 13, 2018 10:11 PM)wtfrick Wrote:  You should look into using requests instead of selenium.

PM me your Discord if you need help.

Sent my discord.


RE: Python bot for whatsapp spamming. (getting error) - mikeyymooney - Sep 14, 2018

(Sep 13, 2018 09:26 PM)kookur Wrote:  Not not worked. I was following this video :

That should work, I watched the video and his code is identical to the one I provided. Perhaps there is another issue with your code.


RE: Python bot for whatsapp spamming. (getting error) - kookur - Sep 14, 2018

(Sep 14, 2018 06:47 AM)mikeyymooney Wrote:  That should work, I watched the video and his code is identical to the one I provided. Perhaps there is another issue with your code.

Can you post the exact complete code, So i can copy paste and check it.


RE: Python bot for whatsapp spamming. (getting error) - mikeyymooney - Sep 14, 2018

(Sep 14, 2018 06:51 AM)kookur Wrote:  Can you post the exact complete code, So i can copy paste and check it.

Try this one from the Github page. Although it's last update was Nov 29, 2017.

Code
from selenium import webdriver

driver = webdriver.Chrome()
driver.get('I can't post links')

name = input('Enter the name of user or group : ')
msg = input('Enter the message : ')
count = int(input('Enter the count : '))

#Scan the code before proceeding further
input('Enter anything after scanning QR code')

user = driver.find_element_by_xpath('//span[@title = "{}"]'.format(name))
user.click()

msg_box = driver.find_element_by_class_name('input-container')

for i in range(count):
   msg_box.send_keys(msg)
   driver.find_element_by_class_name('compose-btn-send').click()



RE: Python bot for whatsapp spamming. (getting error) - Mohinder - Sep 15, 2018

I made a few bots for WhatsApp. Im quite sure this one is working:

Code
driver.find_element(By.XPATH, '//*[@title="{}"]'.format(chat)).click()

To use By, you need to import it into your script:

Code
from selenium.webdriver.common.by import By

The code above will give you an exception when a user is not found, so you should catch that exception and handle it.

Code
try:
    driver.find_element(By.XPATH, '//*[@title="{}"]'.format(chat)).click()
except NoSuchElementException as e:
    print('User not found, exception: {}'.format(str(e)))

And whenever an existing exception is used, import this into your script. For the above exception the import will be:

Code
from selenium.common.exceptions import NoSuchElementException



RE: Python bot for whatsapp spamming. (getting error) - Oblivious- - Sep 15, 2018

if you still haven't figured this out send me a private message I'll be glad to help


RE: Python bot for whatsapp spamming. (getting error) - kookur - Sep 15, 2018

(Sep 15, 2018 08:08 AM)Oblivious- Wrote:  if you still haven't figured this out send me a private message I'll be glad to help

Mohinder helped me, bot is working fine now mate but if you don't mind i'd still like to add you somewhere and will learn something from you :)