3

I am creating a script for Facebook scraping. I am using Selenium 2.53.6, Gecko driver 0.11.1 with Firefox 50 under Ubuntu 14.04.5 LTS. I have also tried it under Windows 10 using Gecko as well as Chromedriver too, with the same results (that I will describe below) :(

The following code fragment I use that I copied from the original documentation in section Explicitly Waits is:

import datetime, time, sys, argparse
from time import strftime
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
from selenium.webdriver.support.ui import WebDriverWait # available since 2.4.0
from selenium.webdriver.support import expected_conditions as EC # available since 2.26.0
...
...
def main(usrEmail, pwd, numberOfScrolls, secondsWait, searchItem, outFilename):
    # Open Firefox Browser
    binary = FirefoxBinary('/usr/bin/firefox')
    browser = webdriver.Firefox(firefox_binary=binary)
    
    #put browser in specific position
    browser.set_window_position(400, 0)

    # goto facebook
    browser.get("http://www.facebook.com")
    
    #waiting( 5 )
    try:
        element = WebDriverWait(browser, 10).until(EC.presence_of_element_located((By.ID, "u_0_p")))
    finally:
        logging("logging in...")

The problem is that I get this error:

  File "fb.py", line 86, in main
    element = WebDriverWait(browser, 10).until(EC.presence_of_element_located((By.ID, "u_0_p")))
NameError: name 'By' is not defined

As a workaround I am just using delays in a form time.sleep( delay ) and the program works pretty nice, but it would be better if I had the WebDriverWait feature.

Do I miss something obvious or it is a kind of selenium bug or a web browser feature? Any help / clarification will be greatly appreciated!

Thanks for your time!!

1
  • 1
    I've had similar problems. From what I've gathered, not all WebDrivers support the Explicitely.Wait feature. Commented Nov 20, 2016 at 10:02

1 Answer 1

2

Could be your missing the definition of By:

from selenium.webdriver.common.by import By
Sign up to request clarification or add additional context in comments.

3 Comments

Well... embarrassing (as obvious) solutions are very common to a every new programming challenge!! :-) Thank you so much @Moshisho... What misleading me, basically, was the original documentation, that skip this... detail!
If my answer has solved your problem, accepting it will be much appreciated!
Apologies for the delay @Moshito... I just accept it!! ;-) Thank you!

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.