zoukankan      html  css  js  c++  java
  • selenium获取文本的值

      1. try :  
      2.     error_message = driver.find_element_by_xpath("//*[@id='id' and text()='用户名或者密码错误']").is_displayed()  
      3. print "pass"
      4. except Exception as e:  
      5. print "fail"
      6. 方法二,
      7. content = driver.find_element_by_xpath("//*[@id='TANGRAM__PSP_8__error']").text  
      8. try:  
      9. assert content== u'用户名或者密码错误'  
      10. print "pass"
      11. except Exception as e:  
    1. print ("Test fail.", format(e)) 
    • 其他方法(获取input的文本)
    1. 第一种用jQuery的val方法:

        js = "return $('input').val();"

        driver.execute_script(js)

      第二种用jQuery的attr方法:

        js = "return $('input').attr('value');"

        driver.execute_script(js)

      第三种用selenium自带的方法:

        driver.find_element_by_tag_name('input').get_attribute('value')

      第四种,利用selenium webdriver的execute_script方法进行提取。

      driver.execute_script( "window.document.getElementById('txaResultText').value" )
  • 相关阅读:
    ivew-admin 导入excel
    ivew Upload 上传时附带的额外参数
    工厂方法模式
    简单工厂模式
    webpack (1)
    商品格子
    合同签名
    展示图片数组
    使用egg.js和egg-sequelize连接mysql
    egg 连接mysql 在mysql 插入数据
  • 原文地址:https://www.cnblogs.com/hhm8hhm/p/7695824.html
Copyright © 2011-2022 走看看