Pyd
Pyd

Reputation: 6159

Unable to locate send button in whatsapp api

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.

Upvotes: 1

Views: 1768

Answers (1)

cruisepandey
cruisepandey

Reputation: 29362

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

Upvotes: 1

Related Questions