selenium Getting started with Selenium in python

30% OFF - 9th Anniversary discount on Entity Framework Extensions until December 15 with code: ZZZANNIVERSARY9


What is Selenium?

Selenium is a library of commands to help a programmer interface with a browser like a real user.

Things that Selenium does:

Finding element(s) in a webpage's html

  • Finds a single element:

    • driver.find_element_by_css_selector("css.selector.of.element") CSS Selector help
    • driver.find_element_by_xpath("//xpath//of//element") XPATH help
    • driver.find_element_by_name("name_of_element")
    • driver.find_element_by_id("id_of_element")
    • driver.find_element_by_partial_link_text("element_link_text")
    • driver.find_element_by_class_name("class_name_of_element")
    • driver.find_element_by_tag_name("tag_name_of_element")
  • Finds a list of elements:

    • driver.find_elements_by_css_selector("css.selector.of.elements")
    • driver.find_elements_by_xpath("//xpath//of//elements")
    • driver.find_elements_by_name("name_of_elements")
    • driver.find_elements_by_partial_link_text("elements_link_text")
    • driver.find_elements_by_class_name("class_name_of_elements")
    • driver.find_elements_by_tag_name("tag_name_of_elements")
  • Official documentation: selenium-python read the docs

Interact with elements:

"method" represents any of the above methods to find an element or list of elements.

  • click function:

  • send_keys function:

    • driver.find_element_by_method.send_keys("text") sends the String "text" to the element found.
    • driver.find_element_by_method.send_keys(KeyCode.UP) sends the KeyCode for the up arrow key to the element found.

Got any selenium Question?