How To Install Chrome Webdriver For Selenium Python
Selenium supports Python and thus can be utilized equally Selenium WebDriver with Python for testing.
- Python is easy compared to other programming languages, having far less verbose.
- The Python APIs empower you to connect with the browser through Selenium.
- Selenium sends the standard Python commands to unlike browsers, despite variation in their browser'southward pattern.
You can run Selenium with Python scripts for Firefox, Chrome, IE, etc. on unlike Operating Systems.
In this Selenium Python tutorial, y'all will learn-
- What is Python?
- What is Selenium?
- Why to choose Python over Java in Selenium
- How to Install and Configure PyDev in Eclipse
- How to Create Test Scripts in Selenium with Python
What is Python?
Python is a high-level object-oriented scripting language. Information technology is designed in a convenient manner. Python uses simple English keywords, which is easy to translate. It has less syntax complications than any other programming languages.
Encounter some of the examples in the table below.
| Keyword | Pregnant | Usage |
|---|---|---|
| elif | Else if | Else if |
| else | Else | if: X; elif: Y; else: J |
| except | practise this ,If an exception happens, | except ValueError, a: print a |
| exec | Run string as Python | exec 'print "hello world !"' |
What is Selenium?
Selenium is a tool to test your web application. You can practise this in various ways, for instance
- Permit it to tap on buttons
- Enter content in structures
- Skim your site to cheque whether everything is "OK" and so on.
Why to choose Python over Java in Selenium
Few points that favor Python over Java to utilise with Selenium is,
- Java programs tend to run slower compared to Python programs.
- Java uses traditional braces to showtime and ends blocks, while Python uses indentation.
- Java employs static typing, while Python is dynamically typed.
- Python is simpler and more meaty compared to Java.
How to Install and Configure PyDev in Eclipse
PyDev is Python development environment for Eclipse.
Step 1) Got to Eclipse Market place. Aid > Install New Software
The next step is to install "pydev IDE" for eclipse.
Footstep two) In this stride,
- Search for "http://pydev.org/updates" in Work with and and then
- Select all listed Items and click on Next twice
- Accept the Licence Understanding and click Finish.
Stride iii) You may encounter Security Warning, Click on "Install Anyway".
Pace 4) Now, in this stride you will set preferences. With the help of preference selection, you can use Python equally per the project need.
Go to Window > Preferences > PyDev > Interpreter > Python Interpreter.
Let'southward sets the default Python Interpreter. It is just like you need to set java compiler for running a Java code. To change the interpreter proper name, click on Browse for python/pypy exe Button.
Step v) In this step, give the "interpreter name" and the "exe" file path of Python.
- Click on 'Browse' and find python.exe where y'all installed Python.
- Click 'OK' button.
- Select all the Folder and click on OK
- Click on "Employ and Close".
Footstep 6) Make a New Projection in Python. In this step,
- Right click PyDev Bundle Explorer > New.
- Select option others.
- Select "PyDev > PyDev Projection".
- Press 'Next' button.
- Name your Projection
- Click "End".
Y'all can run across the new Python (PyDev) project is created.
Step vii) In this pace,
After creating 'PyDev Project', you will create a new Python package.
- Right click on Projection > New > PyDev Parcel.
- Name your Bundle and Click End.
Footstep 8) If you run across in below screenshot, a new package is created.
After creating a new package, the adjacent step is to createPyDev Module. The module contains some Python files for initialization. These files or functions from the module can be imported into other module. Then, there volition exist no need to re-write the programme again.
Step ix) Createa new PyDev module. Right click on package > New > PyDev module.
Name your Module and click "Terminate".
Select Empty Template and Click "OK".
Footstep 10) Write your code for Selenium with Python as shown below
How to Create Test Scripts in Selenium with Python
In this Selenium WebDriver with Python example, we did automation for "Facebook login page" using the Firefox driver.
Selenium Python Case 1: Login into Facebook
from selenium import webdriver from selenium.webdriver.mutual.keys import Keys user_name = "YOUR EMAILID" countersign = "YOUR PASSWORD" driver = webdriver.Firefox() driver.get("https://world wide web.facebook.com") element = driver.find_element_by_id("e-mail") chemical element.send_keys(user_name) element = commuter.find_element_by_id("pass") chemical element.send_keys(password) element.send_keys(Keys.Render) element.shut() Snapshot of the Lawmaking
Explanation of the code
- Code line ane: From selenium module import webdriver
- Code line 2: From selenium module import Keys
- Code line 3: User is a variable which will be nosotros used to store values of username.
- Lawmaking line 4: Variable "password" will be used to shop values of the password.
- Code line 5: In this line, we are initializing "FireFox" by making an object of it.
- Code line 6: The "driver.get method" volition navigate to a page given by the URL. WebDriver will look until the folio has been completely loaded (that is, the "onload" occasion has let become), before returning control to your test or script.
- Code line 7: In this line, we are finding the element of the textbox where the "email" has to be written.
- Code line 8: Now we are sending the values to the email section
- Code line ix: Aforementioned for the password
- Lawmaking line 10: Sending values to the password section
- Code line xi: element.send_keys(Keys.RETURN) is used to press enter after the values are inserted
- Code line 12: Shut
OUTPUT
The values of the username "guru99" and password entered.
The Facebook page will login with email and password. Page opened (encounter image below)
Instance ii: Login into Facebook & Cheque Title
In this example,
- We will open a login folio.
- Fill up the required field "username" and "password".
- Check Page Championship
from selenium import webdriver from selenium.webdriver.support.ui import WebDriverWait # Step i) Open up Firefox browser = webdriver.Firefox() # Step 2) Navigate to Facebook browser.get("http://www.facebook.com") # Step iii) Search & Enter the Email or Phone field & Enter Password username = browser.find_element_by_id("e-mail") countersign = browser.find_element_by_id("pass") submit = browser.find_element_by_id("loginbutton") username.send_keys("YOUR EMAILID") countersign.send_keys("YOUR PASSWORD") # Step 4) Click Login submit.click() expect = WebDriverWait( browser, 5 ) page_title = browser.title assert page_title == "Facebook" Snapshot of the code
Explanation of the lawmaking:
- Lawmaking line i-2: Import selenium packages
- Code line four: Initialize Firefox by creating an object
- Lawmaking line half dozen: Go login page (Facebook)
- Code line 8-10: Fetch username, password input boxes and submit button.
- Code line xi-12: Enter data into username and password input boxes
- Code line 14: Click on the "Submit" push
- Code line 15: Create wait object with a timeout of 5 sec.
- Code line 16: Capturing the championship from "browser" Object.
- Code Line 17: Testing the captured title string with "Facebook"
Summary:
- Selenium is an open-source web-based automation tool.
- Python language is used with Selenium for testing. It has far less verbose and easy to use than any other programming language
- The Python APIs empower yous to connect with the browser through Selenium
- Selenium can send the standard Python commands to different browsers, despite variation in their browser's pattern.
Source: https://www.guru99.com/selenium-python.html
Posted by: edwardspacts1965.blogspot.com

0 Response to "How To Install Chrome Webdriver For Selenium Python"
Post a Comment