Reputation: 19
I was trying to send one file using Python Selenium web driver. But I am not able to locate the send button using python. I can see below HTML using inspect:
Also my web whatsapp screen is not progressing after file send screen Whatsapp web screen shot
I used below code:
fileToSend = file
#Get whatsapp contact
WebDriverWait(driver, wait).until(EC.presence_of_element_located((By.CSS_SELECTOR, '.jN-F5')))
search = driver.find_element_by_css_selector('.jN-F5')
search.send_keys(user + Keys.ENTER)
# click to add
driver.find_element_by_css_selector('span[data-icon="clip"]').click()
# add file to send by file path
attach=driver.find_element_by_css_selector('input[type="file"]')
attach.send_keys(fileToSend)
send=self.driver.find_element_by_class_name('yavlE')
Below is html source code :
<div role="button" class="_3hV1n yavlE">
<span data-icon="send-light" class="">
<svg id="Layer_1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 28 24" width="28" height="24">
<path fill="#FFF" d="M5.101 21.757L27.8 12.028 5.101 2.3l.011 7.912 13.623 1.816-13.623 1.817-.011 7.912z"></path>
</svg>
</span>
</div>
Please help.
Thanks, Samir
Upvotes: 1
Views: 6574
Reputation: 1689
You are using the wrong class name in the below step :
self.driver.find_element_by_class_name('yavlE')
Replace the above line with the below locator and try again :
self.driver.find_element_by_xpath("//div[contains(@class, 'yavlE')]");
Still you are getting NoSuchElementException then try to give some delay like below :
from time import sleep
sleep(3)
self.driver.find_element_by_xpath("//div[contains(@class, 'yavlE')]");
I hope it works...
Upvotes: 2