Python Forum
selenium bypass javascript popup box
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
selenium bypass javascript popup box
#1
I am trying to list out my facebook membership groups using selenium, but i cant without bypassing this javascript box. The
   
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.
Recommended Tutorials:
Reply
#2
would blocking push notifications (at least temporary) be OK?
https://support.google.com/chrome/answer...ktop&hl=en
Reply
#3
Can you use expect to answer the required input automatically?
Reply
#4
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.
Recommended Tutorials:
Reply
#5
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])
Reply
#6
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
Recommended Tutorials:
Reply
#7
(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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Selenium - bypass Cloudflare bot detection klaarnou 4 16,242 Jul-29-2023, 01:42 AM
Last Post: scrapingbypass
  Using Python request without selenium on html form with javascript onclick submit but eraosa 0 3,183 Jan-09-2021, 06:08 PM
Last Post: eraosa
  question about using javascript on python selenium Kai 1 1,890 Apr-12-2020, 04:28 AM
Last Post: Larz60+
  Scrapping javascript website with Selenium where pages randomly fail to load JuanJuan 14 7,216 Dec-27-2019, 12:32 PM
Last Post: JuanJuan
  Unable to access javaScript generated data with selenium and headless FireFox. pjn4 0 2,551 Aug-04-2019, 11:10 AM
Last Post: pjn4
  Selenium click on popup button??? GuJu 7 7,897 Jul-20-2019, 09:21 AM
Last Post: Nizam
  How to check HTTP error 500 and bypass SriMekala 3 10,571 May-04-2019, 02:07 PM
Last Post: snippsat
  Issue closing an Modal Alert (popup) leviathan54 8 5,916 Apr-23-2019, 02:00 PM
Last Post: leviathan54
  How can get url from JavaScript in Selenium (Python 3)? m0ntecr1st0 3 4,101 Feb-19-2019, 12:35 AM
Last Post: m0ntecr1st0
  selneium JS bypass metulburr 15 6,911 Nov-05-2018, 10:52 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020