How To Click On A Username Within Web.whatsapp.com Using Selenium And Python
Solution 1:
Traceback (most recent calllast):
File "C:/Users/myName/PycharmProjects/firstpro/whatsAppBot.py", line 17, in<module>user=driver.find_element_by_xpath("//span[@title='{}']".format(name))
The final line of the traceback output tells you what type of exception was raised along with some relevant information about that exception. The previous lines of the traceback point out the code that resulted in the exception being raised.
here we see that it was unable to locate the path you specified
raison why it stopped
Solution 2:
I feel the issue is with the element not being in the viewport, THe user you are trying to access must be not in the view, also try to debug the issue manually, by below steps
- List item
try to locate the xpath //span[@title='Jaden']
and see if you are able to locate it in the dev tools without scrolling the page down.(If it is able to locate after scrolling the you will have to scroll programmatically using javascript executor.)
- Try to see if there is any load time issue and try to implement appropriate explicit wait for the element
Solution 3:
To send a message to a user through WhatsApp web https://web.whatsapp.com/ using Selenium you have to click on the username inducing WebDriverWait for the element_to_be_clickable()
and you can use either of the following Locator Strategies:
Using
CSS_SELECTOR
:driver.get("https://web.whatsapp.com/") name= input("Enter name:") WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div[role='option'] span[title='{}']".format(name)))).click()
Using
XPATH
:driver.get("https://web.whatsapp.com/") name= input("Enter name:") WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@role='option']//span[@title='{}']".format(name)))).click()
Note : You have to add the following imports :
from selenium.webdriver.support.uiimportWebDriverWaitfrom selenium.webdriver.common.byimportByfrom selenium.webdriver.supportimport expected_conditions asEC
Post a Comment for "How To Click On A Username Within Web.whatsapp.com Using Selenium And Python"