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 :)

Sign up to request clarification or add additional context in comments.

Comments

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')

Comments

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 Comments

added it, still no change
@nlper okay, could you try locating the links inside every search result by tag name? s.find_element_by_tag_name("a").
no, it gives Unable to find element with tag name 'a' @alecxe
@nlper okay, thanks, which browser are you using? Also, do you have a "login to facebook" step?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.