Open zooser22 opened 3 years ago
Hello, I'm new using GitHub. I've faced the same issue these last days. I found a solution in other repo using selenium with whatsapp web (can't find it now).
In the whatsapp.py
file, on send_message
definition (and others that can need to be solved) change
search = self.browser.find_element(*WhatsAppElements.search)
By
search = self.browser.find_element_by_xpath('//*[@id="side"]/div[1]/div/label/div/div[2]')
Furthermore, it is needed to change ._1awRl
in line 36 by the CSS element that is being used now (._3LX7r
).
Hope I've been helpful
I have fixed the selectors. Please try now.
Thank you, Visweswaran N
Working, thank you!
@liberticl
Thanks man it`s worked but i think that there is more missed elements such as in :
Send image error :
Message: no such element: Unable to locate element: {"method":"css selector","selector":".bDS3i > div:nth-child(1) > div:nth-child(1) > span:nth-child(1)"} (Session info: chrome=88.0.4324.182) (Driver info: chromedriver=2.41.578737 (49da6702b1de0f6c197e),platform=Windows NT 6.1.7601 SP1 x86)
Fix it by replace :
attach_icon = (By.CSS_SELECTOR, ".bDS3i > div:nth-child(1) > div:nth-child(1) > span:nth-child(1)")
with :
attach_icon = (By.CSS_SELECTOR, "._2C9f1 > div:nth-child(1) > div:nth-child(1) > span:nth-child(1)")
Send file error :
Message: no such element: Unable to locate element: {"method":"xpath","selector":"/html/body/div[1]/div/div/div[4]/div/header/div[3]/div/div[2]/span/div/div/ul/li[3]/button/input"} (Session info: chrome=88.0.4324.182) (Driver info: chromedriver=2.41.578737 (49da6702b1de0f6c197e),platform=Windows NT 6.1.7601 SP1 x86)
i think it`s need more work on fixing those elements !
Thank you @zooser22 , I will work on this fix!
Regards, Visweswaran N
I appreciate your hard work for supporting this script
I suggest to add function to Send Anonymous picture using this code :
# Send Anonymous Picture
def send_file_x(self, phone, text,picture_location, caption=None):
payload = urlencode({"phone": phone, "text": text, "source": "", "data": ""})
print (payload)
self.browser.get("https://web.whatsapp.com/send?"+payload)
time.sleep(1)
try:
Alert(self.browser).accept()
except:
print("No alert Found")
time.sleep(5)
try:
send_file_xpath = '/html/body/div[1]/div/div/div[2]/div[2]/span/div/span/div/div/div[2]/span/div/div/span'
attach_type_xpath = '/html/body/div[1]/div/div/div[4]/div/footer/div[1]/div[1]/div[2]/div/span/div/div/' \
'ul/li[1]/button/input'
# open attach menu
attach_btn = self.browser.find_element(*WhatsAppElements.attach_icon)
attach_btn.click()
# Find attach file btn and send screenshot path to input
time.sleep(1)
attach_img_btn = self.browser.find_element_by_xpath(attach_type_xpath)
# TODO - might need to click on transportation mode if url doesn't work
attach_img_btn.send_keys(picture_location) # get current script path + img_path
time.sleep(1)
if caption:
caption_xpath = "/html/body/div[1]/div/div/div[2]/div[2]/span/div/span/div/div/div[2]/div[1]/span/" \
"div/div[2]/div/div[3]/div[1]/div[2]"
send_caption = self.browser.find_element_by_xpath(caption_xpath)
send_caption.send_keys(caption)
send_btn = self.browser.find_element_by_xpath(send_file_xpath)
send_btn.click()
time.sleep(5)
self.browser.quit()
except (NoSuchElementException, ElementNotVisibleException) as e:
print(str(e))
That is great I am working on it!
Regards, Visweswaran N
Hi ...
i can`t execute the script and it show error msg "selenium.common.exceptions.TimeoutException: Message:"
My Simple script ( To send Message ) :
from whatsapp import WhatsApp whatsapp = WhatsApp(100, session="mysession") print(whatsapp.send_message("Same",":heart: Good!"))
first cmd output : https://b.top4top.io/p_1887puw2p1.png
its open whatsapp web page but after a while it show me error : https://c.top4top.io/p_18876h5wc2.png
DevTools listening on ws://127.0.0.1:52819/devtools/browser/eb05022d-aacf-45aa-8 7bd-a822c0d99afa [0302/121025.282:ERROR:gl_surface_egl.cc(773)] EGL Driver message (Error) eglQue ryDeviceAttribEXT: Bad attribute. Traceback (most recent call last): File "XXXXXXXXXXXXXXX\Simple-Yet-Hackable-WhatsApp-api-master\test.py" , line 2, in <module> whatsapp = WhatsApp(50, session="mysession") File "XXXXXXXXXXXXXXX\Simple-Yet-Hackable-WhatsApp-api-master\whatsapp .py", line 61, in __init__ WhatsAppElements.search)) File "XXXXXXXXXXXXXXX\Python\Python37-32\lib\site-packa ges\selenium\webdriver\support\wait.py", line 80, in until raise TimeoutException(message, screen, stacktrace) selenium.common.exceptions.TimeoutException: Message:
with no more actions on the whatsapp web page, So please help me to solve this issues !