I am trying to automate WhatsApp group joining using selenium and python. I can almost reach the final page but can't find the Join group button. This is my python code. Please note that first I'm logging in to WhatsApp using a 5 seconds wait time.
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
# create webdriver object
driver = webdriver.safari.webdriver.WebDriver(quiet=False)
driver.get("https://web.whatsapp.com/")
import time
time.sleep(5)
driver.get("https://chat.whatsapp.com/invite/ANY_WA_GROUP_LINK")
# create action chain object
action = ActionChains(driver)
element = driver.find_element_by_link_text("Join Chat")
action.click(on_element = element)
action.perform()
element = driver.find_element_by_link_text("use WhatsApp Web")
action.click(on_element = element)
action.perform()
element = driver.find_element_by_link_text("Join group")
action.click(on_element = element)
action.perform()
Following is the error that I am getting.
Traceback (most recent call last):
File "basic.py", line 25, in <module>
element = driver.find_element_by_link_text("Join group")
File "/Users/Home/WorkSpace/anaconda3/envs/env_auto/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 428, in find_element_by_link_text
return self.find_element(by=By.LINK_TEXT, value=link_text)
File "/Users/Home/WorkSpace/anaconda3/envs/env_auto/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 976, in find_element
return self.execute(Command.FIND_ELEMENT, {
File "/Users/Home/WorkSpace/anaconda3/envs/env_auto/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/Users/Home/WorkSpace/anaconda3/envs/env_auto/lib/python3.8/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message:
In case your locator is correct you are missing the wait / delay before element = driver.find_element_by_link_text("Join Chat")
.
So, just try adding
time.sleep(5)
before
element = driver.find_element_by_link_text("Join Chat")
UPD: Try this:
element = driver.find_element_by_xpath('//div[contains(text(),'Join group')]')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.