# -*- coding:utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.by import By
driver=webdriver.Firefox()
driver.get("http://www.baidu.com")
driver.find_element_by_id("kw").send_keys("selenium")
driver.find_element_by_id("su").click()
driver.find_element_by_name("wd")
driver.find_element_by_class_name("s_ipt")
driver.find_element_by_link_text("新闻")
driver.find_element_by_partial_link_text("新")
driver.find_element_by_tag_name("input")
driver.find_element_by_xpath("//*[@class='wd']")
driver.find_element_by_css_selector("span.bg s_btn_wr>input#su")
driver.find_element(By.ID,"kw")
driver.find_element(By.NAME,"wd")
driver.find_element(By.CLASS_NAME,"s_ipt")
driver.find_element(By.CSS_SELECTOR,"span.bg s_btn_wr>input#su")
driver.find_element(By.LINK_TEXT,"新闻")
driver.find_element(By.PARTIAL_LINK_TEXT,"新")
driver.find_element(By.TAG_NAME,"input")
driver.find_element(By.XPATH,"//*[@class='bg s_btn']")
driver.quit()
selenium+python定位元素示例
最新推荐文章于 2022-07-15 13:15:00 发布