1

I am trying to browse facebook via selenium in python. Here is my script so far.

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

usr = ""# I have put 3 different accounts and tested it. Same error
pwd = ""

driver = webdriver.Chrome('E:\python_libs\chromedriver.exe')

driver.get("https://www.facebook.com")

assert "Facebook" in driver.title

elem = driver.find_element_by_id("email")
elem.send_keys(usr)
elem = driver.find_element_by_id("pass")
elem.send_keys(pwd)
elem.send_keys(Keys.RETURN)



elem = driver.find_element_by_css_selector(".input.textInput")
elem.send_keys("Posted using Python's Selenium WebDriver bindings!")



elem = driver.find_element_by_css_selector(".selected")

elem.click()
time.sleep(5)




driver.close()

This script when run on windows with chromedriver obtained and correctly installed returns an error.

Traceback (most recent call last):
File "C:\Users\Home\Desktop\facebook_post.py", line 28, in <module>
elem.click()
File "C:\Python27\lib\site-packages\selenium-2.42.0-           py2.7.egg\selenium\webdriver\remote\webelement.py", line 60, in click
self._execute(Command.CLICK_ELEMENT)
File "C:\Python27\lib\site-packages\selenium-2.42.0-    py2.7.egg\selenium\webdriver\remote\webelement.py", line 370, in _execute
return self._parent.execute(command, params)
File "C:\Python27\lib\site-packages\selenium-2.42.0-py2.7.egg\selenium\webdriver\remote\webdriver.py", line 172, in execute
self.error_handler.check_response(response)
File "C:\Python27\lib\site-packages\selenium-2.42.0-py2.7.egg\selenium\webdriver\remote\errorhandler.py", line 164, in check_response
raise exception_class(message, screen, stacktrace)
WebDriverException: Message: u'unknown error: Element is not clickable at point (481,     185). Other element would receive the click: <input type="file" class="_n _5f0v" title="Choose a file to upload" accept="image/*" name="file" id="js_0">\n  (Session info: chrome=35.0.1916.114)\n  (Driver info: chromedriver=2.10.267521,platform=Windows NT 6.1     x86)'

I am unable to make head or tail of this. Any help would be appreciated.

The Graph API is not feasible here as I want to browse as myself and not as some application. If however browsing as myself can be done by graph API or some other means, please do tell.

1
  • works in firefox. But why does it not work in chrome? I was simply interested to know the reason for this error. Commented May 25, 2014 at 18:17

1 Answer 1

3

If you're doing this process several times, Selenium has some options in WebDriverWait to not waste too much time and check to see if elements are visible.

Here is the documentation on Waits in Selenium and this is a section of the Python documentation of Selenium that talks about the Expected Conditions classes. It seems that "clickable" is one conditions that you can check for.

In my case, I wrote a simple function that took care of visibility and clicking and called it every time I needed to click on something dynamic.

My example code:

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

Browser = webdriver.Chrome()

def wait_until_visible_then_click(element):
    element = WebDriverWait(Browser,5,poll_frequency=.2).until(
        EC.visibility_of(element))
    element.click()

EDIT:

The links above seem to be nerfed. This is the new documentation on waits and here are the expected conditions docs.

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

1 Comment

NameError: global name 'Browser' is not defined

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.