1

I am trying to get user details from each block as given

driver.get("https://www.facebook.com/public/karim-pathan") wait = WebDriverWait(driver, 10) li_link = [] for s in driver.find_elements_by_class_name('clearfix'): print s print s.find_element_by_css_selector('_8o._8r.lfloat._ohe').get_attribute('href') print s.find_element_by_tag_name('img').get_attribute('src') 

it says:

unable to find element with css selector

any hint appreciable.

    3 Answers 3

    2

    Just a mere guess based on assumption that you are not logged in. You are getting exception cause for all class clearfix, element with ._8o._8r.lfloat._ohe does not exists. So your code isn't reaching the required elements. Anyhow, if you are trying to fetch href and img source of results, you need not iterate over all clearfix cause as suggested by @leo.fcx, your css is incorrect, trying the css provided by leo, you can achieve the desired result as:

    driver.get("https://www.facebook.com/public/karim-pathan") for s in driver.find_elements_by_css_selector('._8o._8r.lfloat._ohe'): // there didn't seemed to iterate over each class of clearfix print s.get_attribute('href') print s.find_element_by_tag_name('img').get_attribute('src') 

    P.S. sorry for any syntax, never explored python binding :)

      2

      Since you are using all class-names that the element applies, adding a . to the beginning of your CSS selector should fix it.

      Try this:

      s.find_element_by_css_selector('._8o._8r.lfloat._ohe') 

      instead of:

      s.find_element_by_css_selector('_8o._8r.lfloat._ohe') 
      0
        2

        Adding to what @leo.fcx pointed about the selector, wait for search results to become visible:

        wait.until(EC.visibility_of_element_located((By.ID, "all_search_results"))) 
        4
        • added it, still no change
          – nlper
          CommentedJul 24, 2015 at 13:46
        • @nlper okay, could you try locating the links inside every search result by tag name? s.find_element_by_tag_name("a").
          – alecxe
          CommentedJul 24, 2015 at 13:49
        • no, it gives Unable to find element with tag name 'a' @alecxe
          – nlper
          CommentedJul 24, 2015 at 13:54
        • @nlper okay, thanks, which browser are you using? Also, do you have a "login to facebook" step?
          – alecxe
          CommentedJul 24, 2015 at 15:15

        Start asking to get answers

        Find the answer to your question by asking.

        Ask question

        Explore related questions

        See similar questions with these tags.