Skip to content

Instantly share code, notes, and snippets.

@leostera
Created August 30, 2012 17:58
Show Gist options
  • Save leostera/3535568 to your computer and use it in GitHub Desktop.
Save leostera/3535568 to your computer and use it in GitHub Desktop.
Selenium WebDriver Python Bindings and Facebook Login
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
usr = ""
pwd = ""
driver = webdriver.Firefox()
# or you can use Chrome(executable_path="/usr/bin/chromedriver")
driver.get("http://www.facebook.org")
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("input[value=\"Publicar\"]")
elem.click()
driver.close()
@saidihasan
Copy link

@vivekiyer114 : according to this http://selenium-python.readthedocs.io/api.html driver.find_element_by_css_selector for search and match from css website.

@jebastin4u
Copy link

jebastin4u commented Feb 19, 2017

I got this ERROR

File "new_login.py", line 17, in
elem = driver.find_element_by_css_selector(".input.textInput")
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 437, in find_element_by_css_selector
return self.find_element(by=By.CSS_SELECTOR, value=css_selector)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 752, in find_element
'value': value})['value']
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 236, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/errorhandler.py", line 192, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: .input.textInput

@srcecde
Copy link

srcecde commented Feb 27, 2017

Hi,

I have wrote the script that automates the Facebook login, status updates and likes (can select the user). Have a look at GitHub

Thanks

@HarishGargIndia
Copy link

HarishGargIndia commented Sep 30, 2017

Thank you so much i am able to login my facebook account by python. but can you tell me what does "assert "Facebook" in driver title" mean.
i am very new to python.
i am running below code to login one site named - Trivago could anyone help me.
code..

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

usr = "Trivago"
pwd = "123"

driver = webdriver.Chrome("F:\Training\Python\chromedriver.exe")
driver.get("https://intelligence.trivago.com")
#assert "Trivago" 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)

error -
NoSuchElementException: Message: no such element: Unable to locate element: {"method":"id","selector":"email"}
(Session info: chrome=61.0.3163.100)
(Driver info: chromedriver=2.32.498550 (9dec58e66c31bcc53a9ce3c7226f0c1c5810906a),platform=Windows NT 6.1.7600 x86_64)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment