当前位置:主页 > 软件编程 > Python代码 >

在python中获取div的文本内容并和想定结果进行对比详解

时间:2021-08-03 08:58:25 | 栏目:Python代码 | 点击:

div的内容为:

<div style="background-color: rgb(255, 238, 221);" id="status" class="errors">您输入的用户名或密码有误。</div>

# coding:utf-8
from selenium import webdriver

browser = webdriver.Firefox()
url = 'file:///C:/Users/li/Desktop/hello.html'
browser.get(url)
alert_inf = "您输入的用户名或密码有误。"

s = browser.find_element_by_xpath("//div[@id='status']")
b = s.text
print b

if b.encode('utf-8') == alert_inf:
 print "哈哈哈!ok啦!"
else:
 print "呀,出错了! 不好玩!"

您可能感兴趣的文章:

相关文章