zoukankan      html  css  js  c++  java
  • css定位.py

    from selenium import webdriver
    #引入By类:
    from selenium.webdriver.common.by import By
    driver = webdriver.Chrome()
    #通过class属性定位输入框和百度一下、点表示通过class属性来定位元素:
    driver.find_element_by_css_selector(".s_ipt")
    driver.find_element_by_css_selector(".bg s_btn")

    #通过id属性定位输入框和百度一下、井号表示通过id属性来进行定位元素:
    driver.find_element_by_css_selector("#kw")
    driver.find_element_by_css_selector("#su")

    #通过标签名定位、注意标签名重复概率大:
    driver.find_element_by_css_selector("input")

    #通过父子关系定位父标签是span、查找所有标签名叫input的子元素:
    driver.find_element_by_css_selector("span>input")

    #通过属性定位:
    driver.find_element_by_css_selector("[autocomplete=off")
    driver.find_element_by_css_selector("[name='wd']")
    driver.find_element_by_css_selector("[type='submit']")

    #组合定位、父标签span有一个class属性值叫bg s_ipt_wr下面有一个子元素标签名叫input、子元素的class属性值叫s_ipt、:
    driver.find_element_by_css_selector("span.bg s_ipt_wr>input.s_ipt")
    driver.find_element_by_css_selector("span.bg s_btn_wr>input#su")

    #通过By定位元素、统一调用find_element()方法、通过By来声明定位的方法、传入对应定位方法的定位参数、第一个参数是定位的类型、由By提供、第二个参数是定位的具体方式:
    driver.find_element(By.ID,"kw")
    driver.find_element(By.NAME,"wd")
    driver.find_element(By.CLASS_NAME,"s_ipt")
    driver.find_element(By.TAG_NAME,"inpu")
    driver.find_element(By.LINK_TEXT,"新闻")
    driver.find_element(By.PARTIAL_LINK_TEXT,"新")
    driver.find_element(By.XPATH,"//*[@class='bg s_btn']")
    driver.find_element(By.CSS_SELECTOR,"span.bg s_btn_wr>input#su")
  • 相关阅读:
    Leetcode Substring with Concatenation of All Words
    Leetcode Divide Two Integers
    Leetcode Edit Distance
    Leetcode Longest Palindromic Substring
    Leetcode Longest Substring Without Repeating Characters
    Leetcode 4Sum
    Leetcode 3Sum Closest
    Leetcode 3Sum
    Leetcode Candy
    Leetcode jump Game II
  • 原文地址:https://www.cnblogs.com/zhang-da/p/12210638.html
Copyright © 2011-2022 走看看