python selenium example (boilerplate) getting started. [search shortcut: sel basic ]

Python Selenium enables you to control a web browser using Python. Here's some boilerplate code I use to get started!

from selenium.webdriver.chrome.options import Options
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver import ActionChains

# example of adding options
option = Options()
options.add("--headless")

driver = webdriver.Chrome(options=option, executable_path="path/to/chromedriver.exe")

url = "https://www.codingcroc.com"
driver.get(url)

driver.find_element_by_id('element')
driver.find_element_by_name('element')
driver.find_element_by_xpath('element')
driver.find_element_by_link_text('element')
driver.find_element_by_partial_link_text('element')
driver.find_element_by_tag_name('element')
driver.find_element_by_class_name('element')
driver.find_element_by_css_selector('element')
terms for search bar: sel start

SNAPPED!

SNAPPED!

Comments

  1. driver.find_elements_by_id('element') for selecting multiple elements

    ReplyDelete
  2. Wow, this article is awesome wish to see more like this. Thanks for sharing such information. You can check this out too Boiler Repair service In Chicago. Thank you.

    ReplyDelete
  3. Thanks for your post. It's very helpful post for us. You can also visit Chicago boiler maintenance Chicago for more Victor Steel related information. I would like to thanks for sharing this article here.

    ReplyDelete

Post a Comment

Popular posts from this blog

Append to a json file python

Setup Mailhog mail server on Ubuntu