skip to Main Content

I am trying to scrap something from website (example facebook(not using graph api just doing for learning), so I successfully login and land on front page, where I want to scrap some data, but the problem is when I land on front page, then facebook shows a layer and a box which says “turn on notification”, now without click on any button between “Not Now” or “turn on” I can’t do anything with splinter, and when I tried to click splinter doesn’t do anything because the link of those button are “#”

enter image description here

when hovering on button footer shows this :

enter image description here

and inspect element shows this :

enter image description here

I tried with other account but that shows this layer as first thing after login :

enter image description here

Now I have question how to click on these 2 types of button via splinter or selenium :

first type of button which shows “#” as href

second which chrome shows for block, allow things

My code is :

 from selenium import webdriver
    from splinter import Browser


    web_driver=webdriver.Chrome('/Users/paul/Downloads/chromedriver/chromedriver')
    url = "https://www.example.com"
    browser = Browser("chrome")
    visit_browser = browser.visit(url)

    email_box = '//*[@id="email"]'
    find_1 = browser.find_by_xpath(email_box)
    find_1.fill("[email protected]")
    password_box = '//*[@id="pass"]'
    find_2 = browser.find_by_xpath(password_box)
    find_2.fill("example12345")

    button_sub = '//*[@id="u_0_5"]'
    find_3 = browser.find_by_xpath(button_sub)
    find_3.click()

for testing purpose you can try on “see more button” in trending section on facebook, that also shows “#” how to click that ?

enter image description here

2

Answers


  1. Chosen as BEST ANSWER

    I have solved my problem , since that link was "#" so if i was click via css or other method it was just reloading the page and that layer appear again and again after every reload , But i tried little different solution and i click it by javascript :

    First i tried and find the right element for clicking via js console in chrome :

    document.getElementsByClassName('layerCancel _4jy0 _4jy3 _517h _51sy _42ft')[0].click();
    

    This is working perfect in js console so now i used splinter method "browser.execute_script()" and pass that script as argument to this method.

    browser.execute_script("document.getElementsByClassName('layerCancel _4jy0 _4jy3 _517h _51sy _42ft')[0].click()")
    

    And its working perfect now as i wanted. But still i have not found a way how to click on browser push notification 'Allow" , "Block" etc

    Thanks :)


  2. Not letting me comment because I don’t have enough rep … but have you tried to select the element by class and then performing .click() on it? That might do the trick as the href being “#” probably means the button has another purpose.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search