selenium获取文本的值

it2025-01-06  33

try :      error_message = driver.find_element_by_xpath("//*[@id='id' and text()='用户名或者密码错误']").is_displayed()  print "pass"except Exception as e:  print "fail"方法二,content = driver.find_element_by_xpath("//*[@id='TANGRAM__PSP_8__error']").text  try:  assert content== u'用户名或者密码错误'  print "pass"except Exception as e:  print ("Test fail.", format(e))  其他方法(获取input的文本)

第一种用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" )

转载于:https://www.cnblogs.com/hhm8hhm/p/7695824.html

最新回复(0)