• find_element


    from selenium import webdriver
    driver = webdriver.Chrome()

    #前提,在当前页面当中,不管用哪种定位方式,一定要是唯一的
    #八种定位方式:#id、#name、#class_name、#input3(tag_name、link_text、partial_link_text)、#xpath、css

    #id
    driver.find_element_by_id("kw")
    driver.find_element_by_css_selector("#kw") # 井号表示ID

    #name
    driver.find_element_by_name("wd")
    driver.find_element_by_css_selector("input[@name='wd']") #xpath
    driver.find_element_by_css_selector("input[name='wd']") #css

    #class
    driver.find_element_by_class_name("s_ipt")
    driver.find_element_by_css_selector("input[@name='s_ipt']")#xpath
    driver.find_element_by_css_selector(".s_ipt") #css


    #input3种
    driver.find_element_by_tag_name("text")

    driver.find_element_by_link_text("新闻")

    driver.find_element_by_partial_link_text("闻")

    #xpath 和 css

    #绝对路径
    driver.find_elements_by_xpath("/html/body/div/div/div/div/form/span/iput")
    driver.find_elements_by_xpath("/html/body/div/div/div/div/form/span[1]/input[6]")

    #id
    driver.find_element_by_xpath("//*[@id='kw']")
    driver.find_element_by_xpath("//input[@id='kw']")
    driver.find_element_by_css_selector("#kw") # 井号表示ID
    driver.find_element_by_css_selector("input[name='wd']") #css
    driver.find_element_by_css_selector(".s_ipt") #css

    #name
    driver.find_element_by_xpath("//input[@name='wd']")

    driver.find_element_by_xpath("//span[@class=]")


    """
    <input id="kw" name="wd"/>
    <input id="kw" name="bb"/>
    <input aa="aa" name="wd"/>
    """

    driver.find_element_by_xpath("//[@id='kw' and @name='wd']")


    #CSS用法
    driver.find_element_by_css_selector("html > body> div> div> div> div> form> span[1]/input[6]")
    driver.find_element_by_css_selector("#kw") # 井号表示ID
    driver.find_element_by_css_selector("input[name='wd']") #css
    driver.find_element_by_css_selector(".s_ipt") #css


  • 相关阅读:
    使用ViewPager实现三个fragment切换
    handler
    Android 源码解析之AsyncTask
    android的生命周期
    安卓在SQLiteOpenHelper类进行版本升级和降级
    安卓ListView操作的两种方法
    表格布局TableLayout
    线性布局和相对布局
    遇到tomcat端口被占用问题解决方案
    easyUI笔记09.03
  • 原文地址:https://www.cnblogs.com/qiuleizhilianlove/p/9456665.html
Copyright © 2020-2023  润新知