selenium 難定位元素 關於定位一列數據中的某一個


  1. 定義了一個函數findname.py,獲得含有關鍵字的列表名稱,並返回list最大值;
復制代碼
def fnn(names, keys):
    k = []
    for name in names:
        #循環獲得屬性為value的值
        s = name.get_attribute("value")
        #找到包含關鍵字keys的字符串
        if keys in s:
            k.append(s)
    newest = max(k)
    return newest
復制代碼
復制代碼
#先定位到列表,在定位input,返回list
        names = driver.find_element_by_xpath(
            "//*[@id='DataTables_Table_0']/tbody").find_elements_by_tag_name("input")
        #關鍵字keys為zs
        name = findname.fnn(names, "zs")
        driver.find_element_by_link_text(name).click()
復制代碼
  • 字符串包含判斷:關鍵字 in string;

  • 復制代碼
    def fnn(names, keys):
        k = []
        for name in names:
            #循環獲得屬性為value的值
            s = name.get_attribute("value")
            #找到包含關鍵字keys的字符串
            if keys in s:
                k.append(s)
        newest = max(k)
        return newest


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM