Selenium With Python
Selenium With Python
PT Swamedia Informatika
2019
Material List
• Python Fundamental
• Selenium WebDriver with Python
What is Python
Python is a widely used high-level programming language for
general purpose. Python features a dynamic type system and
automatic memory management and supports multiple
programming paradigms, including object-oriented, imperative,
functional programming, and procedural styles. It has a large and
comprehensive standart library.
What Python can do ?
● Web Development (server-side),
● Software Development,
● Mathematics,
● System Scripting
Why Python ?
● Python works on different platforms (Windows, Mac, Linux, Raspberry Pi, etc).
● Python has a simple syntax similar to the English language.
● Python has syntax that allows developers to write programs with fewer lines than
some other programming languages.
● Python runs on an interpreter system, meaning that code can be executed as soon
as it is written. This means that prototyping can be very quick.
● Python can be treated in a procedural way, an object-orientated way or a
functional way.
Current Python Version
● Python 3.x is the current version and is under active
development
● Python 2.x is the legacy version and will receive only security
updates until 2020
Python Installation
Install the current Python version https://www.python.org/downloads/
Python Editor
• IDLE is a simple editor for Python, that comes bundled with
Python
• Online Python shell https://www.python.org/shell/
• Using favorite IDE like Sublime, Visual Studio Code, or
Pycharm
<variable name> = <value> ● # String
● # Integer name = 'John Doe'
a=2 print(name)
print(a) # Output: John Doe
# Output: 2 ● # Boolean
● # Floating point q = True
pi = 3.14 print(q)
print(pi) # Output: True
# Output: 3.14 ● # Empty value or null data type
● # String x = None
c = 'A' print(x)
print(c) # Output: None
# Output: A
Block Indentation in Python
Python uses indentation to define control and loop constructs. This contributes to
Python's readability, however, it requires the programmer to pay close attention to the
use of whitespace.
Python uses the colon symbol ( : ) and indentation for showing where blocks of code
begin and end. That is, blocks in Python, such as functions, loops, if clauses and other
constructs, have no ending identifiers. All blocks start with a colon and then contain the
indented lines below it.
Block Indentation in Python
Casting
Python Strings
● String literals in python are surrounded by either single quotation marks, or double
quotation marks. 'hello' is the same as "hello"
● Strings in Python are arrays of bytes representing unicode characters
● Python does not have a character data type, a single character is simply a string
with a length of 1. Square brackets can be used to access elements of the string.
Python Strings
Get the character at position 1 Substring. Get the characters from
position 2 to position 5
Python Strings
There are a lot of methods that can use string operation
Python allows for command line input.
like :
Below code will ask for your name and
● strip() method to remove whitespace in string
print it into the terminal
character
● len() method to get size of a string
● lower() method to make a return of string to be
lower case
● upper() method to make a return of string to be
upper case
● replace() method to replace a string with another
string
● split() method to split a string into substrings
Python Operator
Operators are used to perform operations on variables and values.
Python divides the operators in the following groups :
● Arithmetic operators
● Assignment operators
● Comparison operators
● Logical operators
● Identity operators
● Membership operators
● Bitwise operators
Python Arithmetic Operators
Arithmetic operators are used with numeric values to perform common mathematical
operations
Python Assignment Operators
Assignment operators are used to assign values to variables
Python Comparator Operators
Comparison operators are used to compare two values :
Python Logical Operators
Logical operators are used to combine conditional statements :
Python Identity Operators
Identity operators are used to compare the objects, not if they are equal, but if they are
actually the same object, with the same memory location :
Python Membership Operators
Membership operators are used to test if a sequence is presented in an object :
Python Bitwise Operators
Bitwise operators are used to compare (binary) numbers :
Python Array (list)
Array is a special variable, which can
hold more than one value at a time.