Python Forum

Full Version: selenium bypass javascript popup box
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am trying to list out my facebook membership groups using selenium, but i cant without bypassing this javascript box. The
[attachment=189]
attempting to proceed without taking care of this box causes
Error:
Traceback (most recent call last): File "test2.py", line 52, in <module> soup = BeautifulSoup(r.page_source, 'lxml') AttributeError: 'NoneType' object has no attribute 'page_source'
Then i added the browser.switch_to_alert().accept() but now i get a no alert open error
Error:
File "test2.py", line 50, in <module> alert.accept() File "/home/metulburr/.local/lib/python2.7/site-packages/selenium/webdriver/common/alert.py", line 90, in accept self.driver.execute(Command.ACCEPT_ALERT) File "/home/metulburr/.local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in execute self.error_handler.check_response(response) File "/home/metulburr/.local/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 194, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.NoAlertPresentException: Message: no alert open (Session info: chrome=58.0.3029.110) (Driver info: chromedriver=2.29.461571 (8a88bbe0775e2a23afda0ceaf2ef7ee74e822cc5),platform=Linux 4.4.0-78-generic x86_64)
r = browser.get('https://www.facebook.com/groups/?category=groups')
time.sleep(DELAY)
alert = browser.switch_to_alert()
alert.accept()

for _ in range(100): #scroll to make all groups visible
    browser.execute_script("window.scrollTo(0, document.body.scrollHeight);")

soup = BeautifulSoup(r.page_source, 'lxml')
print(soup.find("div", {"id": "group-discover-card-right-columnmembership"}))
Usually i would just find the XPath to the submit/ok button and select it but with the method i dont think you can see the source of this.
would blocking push notifications (at least temporary) be OK?
https://support.google.com/chrome/answer...ktop&hl=en
Can you use expect to answer the required input automatically?
well i plan on using phantomjs afterwords. Im just using chrome to see what the html is at the time the script executes. I have tried manually allow/block, but the following execution it comes back every time.
Not sure if if look upon as alert.
Then you have to switch window and probably in combo with  window_handles.
driver.switch_to.window(window_name)
Something like this should get the latest open window.
driver.switch_to_window(driver.window_handles[-1])
Doesnt switch to window create a new tab basically? I tried loading a new page, but the javascript popup shows on any page loaded to facebook
(Jun-02-2017, 05:52 PM)metulburr Wrote: [ -> ]Doesnt switch to window create a new tab basically?
It can also handle a pop up window,which it's not an alert.
Now do it look like an alert,so what you have done should work.
Here some alert test.