How to check if some text is present on a web page using selenium 2?

后端 未结 3 1579
灰色年华
灰色年华 2021-02-07 03:10

Hi I am using selenium to automate test on web pages. I am using selenium 2 and python and would like to have answers in this framework only. SO how do I check whether some text

3条回答
  •  醉梦人生
    2021-02-07 03:25

    You can use driver.page_source and a simple regular expression to check if the text exists:

    import re    
    src = driver.page_source
    text_found = re.search(r'text_to_search', src)
    self.assertNotEqual(text_found, None)
    

提交回复
热议问题