I'm trying to scrap WhatsApp using python selenium. I'm trying to find name by locating the search box and typing the name over there. But I'm getting error as Message: Element <div class="gQzdc _3sdhb"> is not reachable by keyboard.
The code is:
from selenium import webdriver as wd
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait as wdw
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import TimeoutException
import base64
import time
print("Scan the QR code then come here.")
browser = input("Enter your fav. browser(Firefox/Chrome): ")
if browser == "Firefox":
driver = wd.Firefox() # open firefox
elif browser == "Chrome":
driver = wd.Chrome()
else:
print("Choose between Firefox/Chrome.")
driver.get("https://web.whatsapp.com/")
try:
element = wdw(driver, 10).until(
EC.title_contains("WhatsApp")
)
try:
print("Scan the QR code then proceed.")
contact_name = input("Enter the contact/group name \nwhose data you want scrap: ")
try:
user = driver.find_element_by_xpath('//span[@title = "{}"]'.format(contact_name))
except Exception as e:
search_box = wdw(driver, 50).until(
lambda driver : search_box)
search_box.click()
search_box.send_keys(contact_name)
user = driver.find_element_by_xpath('//span[@title = "{}"]'.format(contact_name))
wdw(driver, 50).until(lambda driver: user)
except Exception as e:
print(e)
driver.quit()
finally:
driver.quit()
I get to know that WebDriverWait
will be helpful but I don't know how to use it as I don't think no new elements appear when we select the search button.