0% found this document useful (0 votes)
41 views

Important Selenium With Python Operations

This document outlines important Selenium operations for automating web browsers using Python. It covers setup and configuration of browsers like Chrome, Firefox, and Edge. It also covers finding elements, interacting with elements, handling alerts and windows, navigation commands, dropdowns, mouse and keyboard actions, implicit and explicit waits, cookies, frames, executing JavaScript, taking screenshots, desired capabilities, touch actions, proxies, logs, remote drivers, and more.

Uploaded by

Carlos
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views

Important Selenium With Python Operations

This document outlines important Selenium operations for automating web browsers using Python. It covers setup and configuration of browsers like Chrome, Firefox, and Edge. It also covers finding elements, interacting with elements, handling alerts and windows, navigation commands, dropdowns, mouse and keyboard actions, implicit and explicit waits, cookies, frames, executing JavaScript, taking screenshots, desired capabilities, touch actions, proxies, logs, remote drivers, and more.

Uploaded by

Carlos
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

#_ important Selenium with Python Operations [ +100 ]

Setup and Configuration:

● webdriver.Chrome(): Start Chrome browser.


● webdriver.Firefox(): Start Firefox browser.
● webdriver.Edge(): Start Edge browser.
● webdriver.Safari(): Start Safari browser.
● driver.get(): Navigate to a URL.
● driver.quit(): Close and exit the browser.
● driver.close(): Close the current window.

Browser Window Operations:

● driver.maximize_window(): Maximize the browser window.


● driver.minimize_window(): Minimize the browser window.
● driver.fullscreen_window(): Make the browser go fullscreen.
● driver.set_window_size(): Set window size.
● driver.set_window_position(): Set the window's starting position.

Finding Elements:

● driver.find_element_by_id(): Find an element by its ID.


● driver.find_element_by_name(): Find an element by its name
attribute.
● driver.find_element_by_class_name(): Find by class name.
● driver.find_element_by_tag_name(): Find by tag name (e.g., <a>).
● driver.find_element_by_link_text(): Find by exact link text.
● driver.find_element_by_partial_link_text(): Find by partial link
text.
● driver.find_element_by_xpath(): Find using an XPath expression.
● driver.find_element_by_css_selector(): Find using a CSS selector.
● driver.find_elements_by_...(): Methods to find multiple elements.

Element Interactions:

● element.click(): Click on an element.

By: Waleed Mousa


● element.send_keys(): Type into an input box.
● element.clear(): Clear the text of an input box.
● element.submit(): Submit a form.
● element.get_attribute(): Get an attribute from the element.
● element.text: Get the text content of an element.
● element.is_displayed(): Check if an element is visible.
● element.is_enabled(): Check if an element is enabled.
● element.is_selected(): Check if an element (like a checkbox) is
selected.

Working with Alerts and Pop-ups:

● driver.switch_to.alert: Switch to an alert.


● alert.accept(): Accept the alert.
● alert.dismiss(): Dismiss the alert.
● alert.send_keys(): Send text to an alert.
● alert.text: Get text of the alert.

Navigation Commands:

● driver.back(): Navigate back.


● driver.forward(): Navigate forward.
● driver.refresh(): Refresh the current page.
● driver.current_url: Get the current URL.
● driver.title: Get the title of the current page.

Handling Dropdowns and Select Elements:

● Select(element): Initialize the Select class.


● select.select_by_index(): Select by index.
● select.select_by_value(): Select by value.
● select.select_by_visible_text(): Select by visible text.
● select.deselect_all(): Deselect all selected options.

Mouse Actions:

● ActionChains(driver): Create a new action chain.


● actions.click(): Click an element.
By: Waleed Mousa
● actions.double_click(): Double click an element.
● actions.context_click(): Right click on an element.
● actions.drag_and_drop(): Drag and drop.
● actions.move_to_element(): Hover over an element.

Keyboard Actions:

● actions.send_keys(): Send keys.


● actions.key_down(): Press a key down.
● actions.key_up(): Release a key.
● Keys.RETURN, Keys.TAB, etc.: Special key codes.

Wait Strategies:

● WebDriverWait(driver, timeout): Explicit wait.


● expected_conditions.presence_of_element_located(): Wait for an
element to be present.
● expected_conditions.element_to_be_clickable(): Wait for an element
to be clickable.
● driver.implicitly_wait(): Implicitly wait for a certain amount of
time.

Cookies:

● driver.get_cookies(): Get all cookies.


● driver.get_cookie(name): Get a cookie by name.
● driver.delete_cookie(name): Delete a cookie by name.
● driver.delete_all_cookies(): Delete all cookies.
● driver.add_cookie(): Add a cookie.

Frames and Windows:

● driver.switch_to.frame(): Switch to a frame.


● driver.switch_to.default_content(): Switch back to the main
content.
● driver.switch_to.window(): Switch to another window or tab.
● driver.window_handles: Get handles of open windows/tabs.

By: Waleed Mousa


Execute JavaScript:

● driver.execute_script(): Execute JavaScript on the current page.


● driver.execute_async_script(): Asynchronously execute JavaScript.

Screenshot:

● driver.save_screenshot(): Save a screenshot.


● element.screenshot(): Take a screenshot of a specific element.

Advanced Capabilities:

● DesiredCapabilities(): Set desired capabilities for the driver.


● driver.set_page_load_timeout(): Set a timeout for page loading.

Touch Actions:

● TouchActions(driver): Initialize touch actions.


● touch.tap(): Tap on an element.
● touch.scroll_from_element(): Scroll from one element to another.

Working with Proxy:

● Proxy(): Create a new proxy configuration.

Logging and Events:

● driver.logs: Access logs.


● driver.get_log(): Get a specific type of logs (e.g., "browser").

Service and Driver Configuration:

● service.Service(): Create a new driver service.


● service.command_line_args(): Get command-line arguments for the
service.

Mobile Emulation and Remote Drivers:

● webdriver.Remote(): Connect to a remote Selenium server.

By: Waleed Mousa


● MobileEmulation(): Emulate a mobile device.

Webdriver Manager:

● webdriver_manager.chrome.ChromeDriverManager(): Automatically
manage ChromeDriver.
● webdriver_manager.firefox.GeckoDriverManager(): Manage GeckoDriver
for Firefox.

Managing Timeouts:

● driver.set_script_timeout(): Set a timeout for scripts.


● driver.set_page_load_timeout(): Set a timeout for page loading.

Working with Extensions:

● chrome_options.add_extension(): Add a Chrome extension.

Miscellaneous:

● driver.switch_to.active_element: Switch to the active element.


● driver.page_source: Get the page's source code.
● driver.get_window_position(): Get the current window position.
● driver.get_window_rect(): Get the window's size and position.
● driver.get_window_size(): Get the window size.
● driver.get_screenshot_as_png(): Get a screenshot as a PNG.
● driver.get_screenshot_as_base64(): Get a screenshot as base64.
● driver.get_screenshot_as_file(): Save a screenshot to a file.
● driver.get_cookies(): Get all cookies for the current domain.
● driver.add_cookie(): Add a cookie.
● driver.delete_cookie(): Delete a cookie.
● driver.delete_all_cookies(): Delete all cookies.

By: Waleed Mousa

You might also like