2. Clear Concept Using Python Selenium

A Facebook Login Program:
_______________________________________________________

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

driver = webdriver.Firefox()
driver.get("http://www.facebook.com")
elem = driver.find_element_by_id("email")
elem.send_keys("email@gmail.com")
elem2 = driver.find_element_by_id("pass")
elem2.send_keys("your password")
elem3 = driver.find_element_by_xpath("//input[@value='Log In']")
elem3.click()
driver.quit()

There is nothing new in this example. You can easily understand what is going on if you had read the last topics carfully.
In elem3 we have located the element using xpath. Don't worry about this term if you don't know what is xpath.
Xpath is a language to locate the elements in the webpages.

I suggest you to must learn Xpath if you want to be perfect in web automation.

elem3.click() is a function which work as a mouse click on the located element. In this example the elem3.click() perform a click on the Log In  button on facebook page.

This is just a login simulation. You can simulate much more on that like auto Likes, Unlike, Comment or anything using selenium.


 

No comments: