Selenium Forum: Functional And Regression Testing Tool.
Would you like to react to this message? Create an account in a few clicks or log in to continue.
Search
Display results as :
Advanced Search
Latest topics
AEM Training | Free Online DemoWed Apr 21, 2021 5:45 pmazharuddin
c# PageFactory - issue initializing elementsFri Nov 01, 2019 8:40 pmthegoatboy
Selenium making automatic connection to random urlsMon Jul 08, 2019 12:58 pmrepairtechsolutions1
How can we design the custom framework in Selenium RCMon Jun 24, 2019 2:26 pmrandybonnettes
What are the new features in Selenium 3.0Tue Jun 18, 2019 5:37 pmpappyvicky
What are you using Selenium for? Fri Apr 12, 2019 3:52 amzhl
LIMITATIONS OF SELENIUMWed Apr 10, 2019 11:23 amswara
Navigation
 Portal
 Index
 Memberlist
 Profile
 FAQ
 Search

Go down
avatar
Akram Khan
Posts : 1
Join date : 2018-11-05

Selenium WebDriver with Python Cheat Sheet Empty Selenium WebDriver with Python Cheat Sheet

Mon Nov 12, 2018 4:52 pm
This blog article lists Python Selenium WebDriver commands which are helpful to automate Web Application Testing.


Selenium WebDriver Installation

Code:
pip install selenium

WebDriver Initialization

Code:
from selenium import webdriver

firefox = webdriver.Firefox(executable_path='drivers\geckodriver.exe')
chrome = webdriver.Chrome(executable_path='drivers\chromedriver.exe')
edge = webdriver.Edge(executable_path='drivers\MicrosoftWebDriver.exe')
ie = webdriver.Ie(executable_path='drivers\IEDriverServer.exe')

Browser Details


Code:
#Get Browser Name
print(browser.name)

#Get Title
print(browser.title)

#Get Current URL
print(browser.current_url)

#Get Current Window Handle
print(browser.current_window_handle)

#Get All Window Handles
handles_list=browser.window_handles

#Get Page Source
print(browser.page_source)

Maximize and Minimize

Code:
browser.maximize_window()
browser.minimize_window()

Switch to Frame & Window


Code:
browser.switch_to.active_element

browser.switch_to.alert

browser.switch_to.default_content()

# You can pass Window Name or Handle to switch between windows
browser.switch_to.window("window_name")

#You can switch to frame using Name, ID, Index & WebElement
browser.switch_to.frame(1)

browser.switch_to.parent_frame()

Back, Forward & Refresh

Code:
browser.back()
browser.forward()
browser.refresh()

Cookies

Code:
#Get all cookies in a list
cookies_list = browser.get_cookies

#Get a Cookie value
cookie_value = browser.get_cookie("my_cookie")

#Delete a Cookie
browser.delete_cookie("my_cookie")

#Delete all Cookies
browser.delete_all_cookies()

#Add Cookie
browser.add_cookie({"name:value"})

Finding Elements


Code:
#Find Element(s) By ID
element = browser.find_element_by_id("txt_1")
elements = browser.find_elements_by_id("txt_1")

#Find Element By XPATH
browser.find_element_by_xpath("//input")

#Find Element By Link Text
browser.find_element_by_link_text("Products")

#Find Element By Link Text
browser.find_element_by_link_text("Products")

#Find Element By Partial Link Text
browser.find_element_by_partial_link_text('Sign')

#Find Element By Name
browser.find_elements_by_name('foo')

#Find Element By Tag Name
browser.find_elements_by_tag_name('Input')

#Find Element By Class Name
browser.find_elements_by_class_name('breadcrumb')

#Find Element By CSS Selector
browser.find_elements_by_css_selector('input[name="txt"]')

Source: https://codoid.com/selenium-webdriver-python-cheat-sheet/

Thanks
Back to top
Permissions in this forum:
You cannot reply to topics in this forum