How to install selenium in Python using pip?
Recently I came across this tutorial of Web Scraping with python and selenium.
It's a great way of scraping some web content. However it doesn't talk about using PyCharm as IDE to write the code but just uses command prompt for running. And it never uses any IDE while coding like PyCharm and eclipse does. So it might not be very beneficial if we want to use selenium with PyCharm as our primary IDE.
So in this post I will describe how to use pip to install selenium and a couple of libraries in our code by using PyCharm. So for my post, I have taken the scrapy tutorial from the following site as it is very easy and straight forward way to do webscraping. Please refer to this Scraping the internet tutorial.
Step 1: Import Libraries using pip. If you haven't installed pip on your system first run it using following command -. Pip install -r requirements.txt where requirements.txt is a file created when you installed requirements for your project using this command.
Once pip is installed then we need to install some required packages that we will be using for selenium. We will install package selenium through pip using command - pip install selenium==2.32.0
This line will install the selenium version 2.0 with all its dependencies. Please be sure to select appropriate version and corresponding path in case of versions listed here. This should open up a new blank file for us to write the code in.
Then import the selenium module inside your code so that we can use it later on. Import selenium. Step 3: Set selenium browser engine as chrome for the purpose of our project. So we will write - self.driver = webdriver.Chrome()
To set selenium to act like chrome. Now if we open this code in google chrome it will ask us to sign into chrome which we don't need to do as we are logged into chrome already. Now this method will return WebDriver object as selenium.
How to setup selenium in Python?
I have setup selenium for my application which tests the UI of my app.
And now I want to test the API end point which returns JSON response. How can I test that in selenium. Which is the best way of testing the selenium?
Selenium was designed to test websites, not applications. If you want to use it to test your Python application, you need to learn about what it does and does not support, and then either write a very basic mock webdriver based on those principles, or do something different entirely with Selenium.
Why is pip install not working?
I'm using a virtualenv to install packages but when I try to pip install or use the package manager it just sits there and nothing happens.
I am trying to install the package "sqlalchemy". It works fine if I do pip install sqlalchemy on my main Python install but if I try in the virtualenv, nothing happens. I have tried: pip install --upgrade sqlalchemy. Pip install -U sqlalchemy-0.4 pip install sqlalchemy==0.3.8
Pip install sqlalchemy==0.6 pip install sqlalchemy==0.5 and many more. When I run a different command, for example python -m pip list, it works. So the virtualenv is not the issue.
Any help would be appreciated. Make sure you have not added /usr/bin/pip into your PATH environment variable. Grep /usr/bin/ If the second command returns pip with a status code of 0, then there is no problem. If the second command returns pip with a status code of 1 or greater, then you probably do have an issue with your PATH environment variable.
Related Answers
How can we use the Selenium tool with HeadSpin?
Selenium is a tool that is used to automate functional testing. There are two types...
What are 5 Uses of Selenium?
Selenium is a web-automation tool that helps you to test web applications....
How can we use the Selenium tool with HeadSpin?
Selenium is a cross-browser testing automation framework w...