from selenium import webdriver # create a new WebDriver instance driver = webdriver.Chrome() # load a web page driver.get("https://www.example.com") # find a button with a specific class name using a CSS selector button = driver.find_element_by_css_selector(".btn-primary") # click the button button.click() # close the browser driver.quit()
from selenium import webdriver # create a new WebDriver instance driver = webdriver.Chrome() # load a web page driver.get("https://www.example.com") # find a paragraph element with a specific ID using a CSS selector paragraph = driver.find_element_by_css_selector("#intro") # read the text content of the paragraph text = paragraph.text # print the text to the console print(text) # close the browser driver.quit()In this example, the `find_element_by_css_selector` method is used to locate a paragraph element on a web page with a specific ID (indicated by the "#" symbol in the CSS selector). Once the paragraph element is located, the text content of the element is read using the `text` property and printed to the console. The `selenium` package library is used in these examples.