zoukankan      html  css  js  c++  java
  • 遍历某一个标签中的内容;python+selenium定位到列表整体,使用for循环获取列表文本;可用于校验列表是否存在你需要的文本内容

    from selenium import webdriver
    import time
    
    d = webdriver.Chrome()
    d.maximize_window()  # 窗口最大化###登录某网站
    d.get('http://xx.xxx.xx.xx:xxxx/')
    d.find_element_by_xpath('//*[@id="userName"]').send_keys('xxx')
    d.find_element_by_xpath('//*[@id="userPwd"]').send_keys('xxx')
    d.find_element_by_xpath('//*[@id="login"]').click()
    time.sleep(2)###切换表单,进入到操作页面
    d.find_element_by_xpath('//*[@id="menu_ul"]/li[5]/a').click()
    d.switch_to_frame('mainframe2')
    d.find_element_by_xpath('//*[@id="nav-accordion"]/li[2]/a').click()
    d.switch_to_frame('mainframe')
    d.switch_to_frame('vehIframe')###定位到要获取标签的顶级元素,并使用for循环获取
    names = d.find_elements_by_xpath('//*[@id="vehGroupTree_1"]')  #for循环遍历-->重点在这里
    lists = []
    for i in names:
        a = i.text
        lists.append(a)
        print(a, i.get_attribute("href"))  # 打印遍历标签出来的内容和获取href属性的内容
        print(lists)
        elements = '中国'
        if elements in lists:
          print('元素在列表中,成功')
          self.assertIn(elements, lists)
    
    
    
    
  • 相关阅读:
    表单实现仿淘宝搜索应用
    ASCII字符集
    HTTP状态码
    总结get和post区别
    总结Canvas和SVG的区别
    展示github中的页面(Github Pages)
    canvas的beginPath和closePath分析总结,包括多段弧的情况
    12. Integer to Roman
    13. Roman to Integer
    463. Island Perimeter
  • 原文地址:https://www.cnblogs.com/ludundun/p/14087411.html
Copyright © 2011-2022 走看看