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


Messages In This Thread
selenium bypass javascript popup box - by metulburr - Jun-02-2017, 03:29 AM
RE: selenium bypass javascript popup box - by buran - Jun-02-2017, 04:54 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Selenium - bypass Cloudflare bot detection klaarnou 5 16,756 May-30-2024, 01:23 PM
Last Post: parrot22122
  Using Python request without selenium on html form with javascript onclick submit but eraosa 0 3,292 Jan-09-2021, 06:08 PM
Last Post: eraosa
  question about using javascript on python selenium Kai 1 1,981 Apr-12-2020, 04:28 AM
Last Post: Larz60+
  Scrapping javascript website with Selenium where pages randomly fail to load JuanJuan 14 7,616 Dec-27-2019, 12:32 PM
Last Post: JuanJuan
  Unable to access javaScript generated data with selenium and headless FireFox. pjn4 0 2,657 Aug-04-2019, 11:10 AM
Last Post: pjn4
  Selenium click on popup button??? GuJu 7 8,323 Jul-20-2019, 09:21 AM
Last Post: Nizam
  How to check HTTP error 500 and bypass SriMekala 3 11,002 May-04-2019, 02:07 PM
Last Post: snippsat
  Issue closing an Modal Alert (popup) leviathan54 8 6,174 Apr-23-2019, 02:00 PM
Last Post: leviathan54
  How can get url from JavaScript in Selenium (Python 3)? m0ntecr1st0 3 4,279 Feb-19-2019, 12:35 AM
Last Post: m0ntecr1st0
  selneium JS bypass metulburr 15 7,189 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