繁体   English   中英

Python-断言页面中不应该存在的文本字段

[英]Python - Assert a text field that should not exist in the page

您好,我是使用Selenium Webdriver的新手,我正在尝试在python中使用Selenium Webdriver创建测试脚本,并且我正在尝试检查页面中是否不存在某些文本字段。

这是我创建的用于检查文本字段为空还是空的代码:

driver = self.driver
    # Get page by URL
    driver.get(self.base_url + "/userk/mission/")
    # Get page by URL
    driver.get(self.base_url + "/mission/update/123-456-789/")
    self.assertEqual(self.base_url + "/mission/update/123-456-789/", driver.current_url)
    driver.find_element_by_id("discussion-btn").click()
    # Check if text is not present
    self.assertEqual("", driver.find_element_by_xpath("//div[5]/div"))

这是我运行测试时收到的错误:

Traceback (most recent call last):
  File "acttemplate_layouts.py", line 37, in test_task_xml
    self.assertEqual("", driver.find_element_by_xpath("//div[5]/div"))
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 290, in find_element_by_xpath
    return self.find_element(by=By.XPATH, value=xpath)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 744, in find_element
    {'using': by, 'value': value})['value']
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 231, in execute
    response = self.command_executor.execute(driver_command, params)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/remote_connection.py", line 395, in execute
    return self._request(command_info[0], url, body=data)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/remote_connection.py", line 426, in _request
    resp = self._conn.getresponse()
  File "/usr/lib/python2.7/httplib.py", line 1051, in getresponse
    response.begin()
  File "/usr/lib/python2.7/httplib.py", line 415, in begin
    version, status, reason = self._read_status()
  File "/usr/lib/python2.7/httplib.py", line 379, in _read_status
    raise BadStatusLine(line)
BadStatusLine: ''

使用此测试脚本给我一个错误。 请使用正确的语法或方法帮助我。 提前致谢。

在driver.find_element_by_xpath(“ // div [5] / div”)后面添加.text

self.assertEqual("", driver.find_element_by_xpath("//div[5]/div").text)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM