Selenium webdriver methods python

Selenium Python Tutorial

Selenium is a powerful tool for controlling web browsers through programs and performing browser automation. It is functional for all browsers, works on all major OS and its scripts are written in various languages i.e Python, Java, C#, etc, we will be working with Python. Selenium Tutorial covers all topics such as – WebDriver, WebElement, Unit Testing with selenium. This Python Selenium Tutorial covers Selenium from basics to advanced and professional uses.

Why learn Selenium Python ?

  • Open Source and Portable – Selenium is an open source and portable Web testing Framework.
  • Combination of tool and DSL – Selenium is combination of tools and DSL (Domain Specific Language) in order to carry out various types of tests.
  • Easier to understand and implement – Selenium commands are categorized in terms of different classes which make it easier to understand and implement.
  • Less burden and stress for testers – As mentioned above, the amount of time required to do testing repeated test scenarios on each and every new build is reduced to zero, almost. Hence, the burden of tester gets reduced.
  • Cost reduction for the Business Clients – The Business needs to pay the testers their salary, which is saved using automation testing tool. The automation not only saves time but gets cost benefits too, to the business.

Selenium Python Basics

Locating Strategies

  • Locating Single Elements –
    • find_element_by_id()
    • find_element_by_name()
    • find_element_by_xpath()
    • find_element_by_link_text()
    • find_element_by_partial_link_text()
    • find_element_by_tag_name()
    • find_element_by_class_name()
    • find_element_by_css_selector()
    • find_elements_by_name()
    • find_elements_by_xpath()
    • find_elements_by_link_text()
    • find_element_by_partial_link_text()
    • find_elements_by_tag_name()
    • find_elements_by_class_name()
    • find_elements_by_css_selector()

    Action Chains

    • Action Chains Basics
    • click
    • click_and_hold
    • context_click
    • double_click
    • drag_and_drop
    • key_down
    • key_up
    • move_by_offset
    • move_to_element
    • move_to_element_with_offset
    • release
    • reset_actions
    • send_keys

    Advanced in Selenium Python –

    Project Examples

    Selenium WebDriver

    Selenium Webdriver is the parent of all methods and classes used in Selenium Python. It is the driving force of Selenium that allows us to perform various operations on multiple elements on a webpage. Driver has various methods and attributes one can use to automate testing in Selenium Python. To check how to use webdriver, visit – Web Driver in Selenium Python . Various methods one can use in selenium Python are –

    add_cookie Adds a cookie to your current session. back Goes one step backward in the browser history. close Closes the current window. create_web_element Creates a web element with the specified element_id. delete_all_cookies Delete all cookies in the scope of the session.

    Selenium WebElement
    An element can be a tag, property, or anything, it is an instance of class selenium.webdriver.remote.webelement.WebElement . After you find an element on screen using selenium, you might want to click it or find sub-elements, etc. Selenium provides methods around this WebElement of Selenium. To checkout how to use element object in selenium, visit – WebElement in Selenium Python. Various methods one can use with an element in Selenium Python are discussed below –

    Element Methods Description
    is_selected() is_selected method is used to check if element is selected or not. It returns a boolean value True or False.
    is_displayed() is_displayed method is used to check if element it visible to user or not. It returns a boolean value True or False.
    is_enabled() is_enabled method is used to check if element is enabled or not. It returns a boolean value True or False.
    get_property() get_property method is used to get properties of an element, such as getting text_length property of anchor tag.
    get_attribute() get_attribute method is used to get attributes of an element, such as getting href attribute of anchor tag.
    send_keys() send_keys method is used to send text to any field, such as input field of a form or even to anchor tag paragraph, etc.
    click() click method is used to click on any element, such as an anchor tag, a link, etc.
    clear() clear method is used to clear text of any field, such as input field of a form or even to anchor tag paragraph, etc.
    screenshot() screenshot method is used to save a screenshot of current element to a PNG file.
    submit() submit method is used to submit a form after you have sent data to a form.
    value_of_css_property() value_of_css_property method is used to get value of a css property for a element.
    location location method is used to get location of element in renderable canvas.
    screenshot_as_png screenshot_as_png method is used to gets the screenshot of the current element as binary data.
    parent parent method is used to get internal reference to the WebDriver instance this element was found from.
    size size method is used to get size of current element.
    tag_name tag_name method is used to get name of tag you are referring to.
    text text method is used to get text of current element.
    rect rect method is used to get a dictionary with the size and location of the element.
    screenshot_as_base64 screenshot_as_base64 method is used to gets the screenshot of the current element as a base64 encoded string.

    Источник

    The Ultimate Selenium Python Cheat Sheet for Test Automation

    Join

    This article is a part of our Content Hub. For more in-depth resources, check out our content hub on Automation Testing and Selenium Python Tutorial.

    Python is one of the most popular programming languages for Selenium web automation since it provides a simplified syntax and lets you perform more with much less code! Thus, Python and Selenium form an ideal combination to perform web automation testing!

    For starters, Selenium is an open-source framework that is primarily used for automating interactions on the WebElements in the AUT (Application Under Test). Along with Python, Selenium also supports Java, C#, JavaScript, Ruby, and PHP. However, as per my experience, it would be fair to mention that Python will be my most preferred language for Selenium web automation.

    Like me, more & more developers are picking up Python, which is rated as the third-most popular language as per the Stack Overflow Developer Survey 2021. Therefore, a Selenium Python cheat sheet could serve the purpose of providing insights into the useful Selenium Python APIs for realizing automation of websites (or web apps).

    If you’re new to Selenium and wondering what it is then we recommend checking out our guide – What is Selenium?

    In this blog, we explore the Python package that provides Python bindings for the Selenium WebDriver. For installing the Selenium WebDriver package, we use the Python Package Index (PyPI). Run the following command on the terminal to install Selenium for Python:

    Источник

    Читайте также:  Java properties file android
Оцените статью