为什么我不能使用behavior-django在页面上找到元素?

时间:2019-10-30 10:32:37

标签: django python-behave

我只是试图创建我的第一个行为测试,以便在页面上找到链接,以便可以单击它。

我已经使用Chrome和Firefox驱动程序尝试过此操作,但是当我尝试进行以下操作时,我始终收到以下错误消息:

selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: Cookie Policy

我一直在遵循一些指南,但是它们似乎都非常一致,并且发现我的实现与其指令之间没有显着差异。

environment.py中的驱动程序设置如下:

def before_scenario(context, feature):
    context.browser = webdriver.Firefox()
    context.browser.implicitly_wait(10)

失败的步骤是:

@when('I click on "{link_text}"')
def i_click_on(context, link_text):
    link = context.browser.find_element_by_link_text(link_text)
    link.click()

场景如下:

    Scenario: Navigate to cookie policy
        Given I am on the homepage
        When I click on "Cookie Policy"

正在搜索的html的相关部分是:

            <a href="/terms">Terms and Conditions</a>,
            <a href="/privacy">Privacy Policy</a>,
            <a href="/research-policy">Research Policy and Consent</a>,
            and <a href="/cookie-statement">Cookie Policy</a>

产生的错误是:

/Users/olorton/.local/share/virtualenvs/ogg-django-7ceMMn7K/bin/python /Applications/PyCharm.app/Contents/helpers/pycharm/behave_runner.py -t wip --stop --no-skipped --format progress
manage.py behave -fcom.jetbrains.pycharm.formatter /Users/olorton/Code/ogg-django/features -t wip --stop --no-skipped --format progress -n 
Creating test database for alias 'default'...
features/basic_user_flow.feature  
Traceback (most recent call last):
  File "/Users/olorton/.local/share/virtualenvs/ogg-django-7ceMMn7K/lib/python3.7/site-packages/behave/model.py", line 1329, in run
    match.run(runner.context)
  File "/Users/olorton/.local/share/virtualenvs/ogg-django-7ceMMn7K/lib/python3.7/site-packages/behave/matchers.py", line 98, in run
    self.func(context, *args, **kwargs)
  File "features/steps/main_steps.py", line 39, in i_click_on
    link = context.browser.find_element_by_link_text(link_text)
  File "/Users/olorton/.local/share/virtualenvs/ogg-django-7ceMMn7K/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 428, in find_element_by_link_text
    return self.find_element(by=By.LINK_TEXT, value=link_text)
  File "/Users/olorton/.local/share/virtualenvs/ogg-django-7ceMMn7K/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 978, in find_element
    'value': value})['value']
  File "/Users/olorton/.local/share/virtualenvs/ogg-django-7ceMMn7K/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/Users/olorton/.local/share/virtualenvs/ogg-django-7ceMMn7K/lib/python3.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: Cookie Policy

我想念什么吗?

0 个答案:

没有答案