如何使用selenium webdriver python检查文本是否存在?

时间:2017-02-14 10:07:46

标签: python selenium-webdriver

如何查看$('select[name=style_website]').on('change', function (e) { var optionSelected = $("option:selected", this); var valueSelected = this.value; $('.websitestyle_js').val(valueSelected); }); &中是否存在文字? selenium webdriver

我试过了:

python

回复是:

def get_email(browser):

email_check = driver.find_element(By.CLASS_NAME("viewed-user-email")).text

assert user_name in email_check, "Text not found %s" % user_name

1 个答案:

答案 0 :(得分:0)

如果您正在寻找如何检查字符串是否是另一个字符串的子字符串,可以回答:

assert my_email_address in email_check, "Text not found %s" % my_email_address
  1. 使用in
  2. contains关键字
  3. 在assert语句结束时使用消息,而不是在开头。
  4. 完整代码:

    def get_email(browser): 
        email_check = browser.findElement(By.CLASS_NAME("viewed-user-email")).text
        assert my_email_address in email_check, "Text not found %s" % my_email_address
    

    参考文献:

    1. What is the use of "assert" in Python?
    2. Does Python have a string contains substring method?