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

后端 未结 3 1578
灰色年华
灰色年华 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:14

    For those of you who are still interested:

    Generic Solution

    if (text in driver.page_source):
         # text exists in page
    

    unittest:

    assertTrue (text in driver.page_source)
    

    pytest:

    assert (text in driver.page_source) 
    

提交回复
热议问题