html tool

2014年7月14日星期一

selenium WebDriver python test for assertTrue

add:http://stackoverflow.com/questions/7706776/equivalent-of-istextpresent-in-selenium-1-selenium-rc-in-selenium-2-webdriver


def is_text_present(self,text):
    try: el=self.driver.find_element_by_tag_name("body")
    except NoSuchElementException, e: return False
    return text in el.text

[popexizhi:
调用是用为self.is_text_present([查找的字符串]);
1.find_element_by_tag_name() 是返回指定tagname的内容,NoSuchElementException 是查找此tag name的异常
2. 返回text是全部内容吧?[try]一直提示编码问题没有打印出来
3. in的功能是正则吗?还是python 的关键字呢?是个操作符如下解释
[help]
For user-defined classes which do not define __contains__() but do define __iter__(), x in y is true if some value z with x == z is produced while iterating over y. If an exception is raised during the iteration, it is as if in raised that exception.

]     

没有评论:

发表评论