1

I am currently working on a project where I am automating whatsapp messages through url. like this https://wa.me/number_here

whenever i do it normally everything goes fine, but when I try to automate this a whatsapp popup box appears and blocks everything, I mean everything, no right-click no developer options, that is why i cant get the x path of the button on that popup. i have tried (driver.shift_to,alert.close)but it says that there is no such alert. i have tried to find the button by contains(text) method but also did not work. here is my code.

chrome_options = Options()
chrome_options.add_argument('--user-data-dir = user-data') 
chrome_options.add_experimental_option('excludeSwitches', ['enable-automation'])  
chrome_options.add_argument('--disable-notifications')      
chrome_options.add_argument('--disable-popup-blocking')
chrome_options.add_experimental_option('useAutomationExtension', False)

driver = webdriver.Chrome(options=chrome_options, executable_path= driver_path)
wait = WebDriverWait(driver, 60)
contact = f'https://wa.me/{number}'        

    driver.get(contact)      
    time.sleep(3)

    alert = wait.until(EC.alert_is_present())
    alert.accept() 

enter image description here

please help me how to bypass this popup. thanks

Fresco
  • 253
  • 1
  • 5
  • 16
Romeo
  • 5
  • 5

1 Answers1

0

I think, this link can be helpful for you: https://stackoverflow.com/a/19019311/12000849

What I do is to set a conditional delay with WebDriverWait just before the point I expect to see the alert, then switch to it, like this:

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException

browser = webdriver.Firefox()
browser.get("url")
browser.find_element_by_id("add_button").click()

try:
    WebDriverWait(browser, 3).until(EC.alert_is_present(),
                                   'Timed out waiting for PA creation ' +
                                   'confirmation popup to appear.')

    alert = browser.switch_to.alert
    alert.accept()
    print("alert accepted")
except TimeoutException:
    print("no alert")
dukkee
  • 1,112
  • 1
  • 9
  • 17
  • thank you brother I tried this, it gives the message but popup is still there selenium.common.exceptions.TimeoutException: Message: Timed out waiting for PA creation confirmation popup to appear. – Romeo Jan 27 '21 at 18:19
  • @Romeo Did you try to set a bigger timeout? Not 3, but 30 e.g. – dukkee Jan 27 '21 at 18:22
  • shift_to.alert does not work here, it is a different type of box, It blocks mouse click outside of the box. you can only click on the check box and on the buttons available on the popup, you can not click anywhere else – Romeo Jan 27 '21 at 18:24
  • yes i have tried 10 sec also although popup appears immediately – Romeo Jan 27 '21 at 18:25
  • @Romeo As I read now, with 99% we can't move to this popup via selenium...( – dukkee Jan 27 '21 at 19:08
  • please man, its the last hope, actually i am trying to start a new chat through whatsapp web. we can continue messaging if we have have conversation with some one. but what if i want to start chat with 500 new people without saving their number into contact list. i mean this is the only way if we can bypass that popup – Romeo Jan 27 '21 at 19:24
  • @Romeo try maybe this link: https://stackoverflow.com/a/62942891/12000849 – dukkee Jan 27 '21 at 20:44
  • it works dear thanks...... i will try it on windows too thank you very much – Romeo Jan 28 '21 at 17:32