As we know Selenium is an automation tool through which we can automate the browsers by writing some lines of code. It is compatible with all browsers, Operating systems and also its program can be written in any programming language such as Python, Java, and many more.
Selenium provides a convenient API to access Selenium WebDrivers like Firefox, IE, Chrome, Remote etc. The currently supported Python versions are 3.5 and above.
Use pip to install the Selenium package. Just write this below command on Command Prompt.
pip install selenium
Once installation gets done. Open Python Console and just write these two commands for verifying whether Selenium is installed or not.
Webdriver Manager for Python:
Previously, We should download binary chromedriver and Unzip it somewhere on our PC and also set a path. After that, set path to this driver like this:
But Every time, the new version of the driver released, so we need to download a new driver otherwise it will give us errors. For Solving this issue, we need to install webdriver-manager:
pip install webdriver-manager
If we are using chrome driver, then we need to write these lines:
Like Chrome, We have some other browsers also. For Example:
Use with Chromium:
Use with FireFox:
Use with IE:
Use with Edge:
Get all text of the page using Selenium in Python
Let’s learn how to automate the tasks with the help of selenium in Python Programming. Here in this article, We are discussing how to get all text of the page using selenium.
- Import the webdriver from selenium module
- Here, in this article, we will automate the task on Chrome browser. So, We have to import ChromeDriverManager from the webdriver_manager.chrome. Now, We are not required to download any drivers from the internet. This command will automatically download the drivers from the Internet. Currently, Supported WebDriver implementations are Firefox, Chrome, IE, and Remote.
- Installing the Chrome driver and store in the instance of webdriver.
- The driver.get method will navigate to a page given by the URL. WebDriver will wait until the page gets fully loaded before returning control to our program.
- WebDriver gives various ways to find the elements in our page using one of the find_element_by_* methods. For example, Body section of the given page can be located with the help of it’s xpath, we will use the find_element_by_xpath method.
- Finally, for closing the browser window. We will use the driver.close method. One more method, we have driver.exit method which closes entire browsers where driver.close will close only one window tab.
Below is the Implementation:
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course