1

I am trying to send a message through web whatsapp using python selenium.

here is my code.

from selenium import webdriver

import time
browser=webdriver.Chrome()

browser.get("""https://api.whatsapp.com/send?phone=************&text=I'm%20interested%20in%20your%20car%20for%20sale""")
time.sleep(5)
send_btn=browser.find_element_by_id("action-button")
send_btn.click()

this is the send button It is not clicking the send button, it just blinks. please help.

Pyd
  • 6,017
  • 18
  • 52
  • 109

1 Answers1

1

As you have mentioned, you are using XPATH , I would suggest you to use CSS_SELECTOR over XPATH.

This is the code you can try out :

send_button = driver.find_element_by_css_selector('a.button.button--simple.button--primary')
send_button.click()  

UPDATE :
CSS selectors perform far better than Xpath and it is well documented in Selenium community. Here are some reasons,

  1. Xpath engines are different in each browser, hence make them inconsistent.

  2. IE does not have a native xpath engine, therefore selenium injects its own xpath engine for compatibility of its API. Hence we lose the advantage of using native browser features that WebDriver inherently promotes.

For more you refer this SO Link : XPATH VS CSS_SELECTOR

cruisepandey
  • 28,520
  • 6
  • 20
  • 38
  • Okay I will try this.. but What advantage in using CSS selector? – Pyd May 27 '18 at 08:13
  • Thanks for the detail. I will modify with your code. Can we send images like this using WhatsApp API? – Pyd May 27 '18 at 08:26
  • if you can manually do it , you can automate it. I haven't used whatsapp api though. – cruisepandey May 27 '18 at 08:28
  • Yes I can automate it with selenium by finding xpath of the respected contact name but I am trying to send with the phone numbers not with contact names – Pyd May 27 '18 at 08:29
  • Don't go for xpath firstly , use id , classname , tag name , link text, partial link text , css selector then if nothing works out for you , xpath comes to floor. – cruisepandey May 27 '18 at 08:31
  • Ya that's fine.. my problem is to send images to phone numbers which are not saved in my contacts – Pyd May 27 '18 at 08:32
  • Can you send images to phone numbers which aren't saved in your contact manually ? I don't think so – cruisepandey May 27 '18 at 08:33
  • But we can send texts to phone numbers which are not saved using the above WhatsApp API. It's ok leave it. We will find another way – Pyd May 27 '18 at 08:34