断言/VerifyElementPresent是否与Python和WebDriver一起使用? [英] Assert/VerifyElementPresent with Python and WebDriver?

查看:323
本文介绍了断言/VerifyElementPresent是否与Python和WebDriver一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可能只是对从Selenium到WebDriver的更改以及它们各自的文档感到困惑.在文档中有关测试设计的部分中,讨论了使用声明与验证例如AssertElementPresent.但是,在阅读WebDriver教程并开始设置测试时,Python似乎没有提供此功能.我是否忽略了文档中的内容,这是否不适用于WebDriver,不适用于使用python,我应该使用python的功能并且不声明/验证来自selenium的命令等吗?

I may just be confused by the change from Selenium to WebDriver and their respective documentation. In a section about test design in the documentation there is talk of using Assert vs Verify such as AssertElementPresent. However in going through the WebDriver tutorial and beginning to setup tests this does not seem to be available from Python. Am I overlooking something in the documentation, is this not applicable to WebDriver, not applicable to using python, should I use capabilities of python and not assert/verify command from selenium, etc?

推荐答案

webdriver是用于驱动浏览器的库.您要使用的是* find_element *方法来定位元素,然后针对它们断言条件.

webdriver is a library for driving browsers. what you want to use are the *find_element* methods to locate elements and then assert conditions against them.

例如,此代码对元素的内容进行断言:

for example, this code does an assertion on content of an element:

from selenium import webdriver

browser = webdriver.Firefox()
browser.get('http://www.example.com')
element = browser.find_element_by_tag_name('h1')
assert element.text == 'Example Domains'
browser.quit()

  • 请注意,此示例是纯Python,带有未声明的断言.最好使用像python的unittest这样的测试框架,它具有更强大的断言.
  • 这篇关于断言/VerifyElementPresent是否与Python和WebDriver一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆