Mastering Selenium helps you automate your day to day tasks like managing your tweets, texting on Whatsapp and even just googling without opening a browser in just 15-30 lines of Python code. The limits of automation are endless with selenium.
1.1 Selenium bindings in Python
Selenium Python bindings provide a convenient API to access the Selenium Web Driver like Firefox, Chrome, etc.
Pip install Selenium
1.2 Web Drivers
Selenium requires a web driver to communicate with the selected browser. Web Drivers — it is a package for interacting with a web browser. It communicates with a web browser or remote web server over a wired protocol that is common to all. You can check and install your browser`s web drivers.
Chrome: https://sites.google.com/a/chromium.org/chromedriver/downloads Firefox: https://github.com/mozilla/geckodriver/releases Safari: https://webkit.org/blog/6900/webdriver-support-in-safari-10/ pre>
Cutting through the code
The above script is for entering twitter and looking for geeks for geek descriptors.
So let`s see how it works:
1. Opening the browser
2. Instantiating the browser and using the .get function to connect to the website.
3. Find an element can be anything, find an input field or a button and use a selenium function like click (), send_keys (), etc. to interact with the element.
4. Closing the browser
By now, you must have figured out that this automation script works in a iterative way of finding an element and interacting with it. There are various ways to find an element on a web page, you just right click and view the element and copy the element by name, css selector or xpath.
Well, in general, with this, you can create your own automated script for each individual site or a universal script for all your social networks that automates all your actions.
There are no automation limits and the above is just an example to get you guys getting started. So happy programming!