本文介绍了硒:元素不可点击...其他元素将获得点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Django项目上运行Selenium测试时,我开始收到错误消息:

When running Selenium tests on my Django project, I've started to get the error:

selenium.common.exceptions.WebDriverException: Message: Element is not clickable at point (61, 24.300003051757812). Other element would receive the click: <a class="navbar-brand" href="#"></a>

这很奇怪,原因有两个:首先,先前通过的测试,而我尚未编辑代码库的那部分.其次,当弹出Selenium驱动的Firefox窗口并最大化页面时,测试通过.但是,当我让Selenium测试在未最大化Firefox浏览器的情况下运行时,它们将失败.

It is odd for two reasons: First, the tests previously passed and I have not edited that part of the code base. Second, when the Selenium-driven Firefox Window pops up and I maximize the page, the tests pass. But when I let the Selenium tests run with the Firefox browser not maximized, they fail.

我没有使用任何精美的javascript(仅是基本的Bootstrap 3模板),而只是使用了普通的旧html和css.我在Python 3.4上使用Django 1.9.我已经运行pip检查是否已升级到Selenium,并且我是最新的.

I'm not using any fancy javascript (just the basic Bootstrap 3 template), just plain old html and css. I'm using Django 1.9 on Python 3.4. I've run pip to check for upgrades to Selenium, and I'm up to date.

这是一个Pastbin链接,指向我的视图和模板输出的html.

Here is a pastebin link to the html of the output of my view and template.

其中一项失败的测试是:

One of the failing tests is:

def test_create_task_and_check_that_it_shows_up_in_the_task_manager_index_and_filter(self):
        # Create user
        self.user = User.objects.get(username=test_superuser_username)
        # Log the user in
        self.log_user_in(user_object=self.user, password=test_superuser_password)
        self.browser.implicitly_wait(10)
        # Pull up the main task manager page
        self.browser.get(str(self.live_server_url) + reverse('task_manager:index'))
        # Make sure we go to the task manager index
        task_index_url = str(self.live_server_url) + reverse('task_manager:index')
        self.browser.get(task_index_url)
        self.browser.implicitly_wait(4)
        self.assertTrue(str(task_index_url) == self.browser.current_url,
                        msg=('Assertion that current_url is %s failed. Current_url is %s' %
                             (str(reverse('task_manager:index')), self.browser.current_url)))
        # Click the 'add task' button on the sidebar
        add_task_taskbar_button = self.browser.find_element_by_name('add_task_sidebar_link')
        add_task_taskbar_button.click()

最后一行会产生错误:

ERROR: test_create_task_and_check_that_it_shows_up_in_the_task_manager_index_and_filter (tasks.tests.test_functional.SeleniumTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/mint/Python_Projects/[project_name]/tasks/tests/test_functional.py", line 94, in test_create_task_and_check_that_it_shows_up_in_the_task_manager_index_and_filter
    add_task_taskbar_button.click()
  File "/home/mint/Python_Projects/venv/lib/python3.4/site-packages/selenium/webdriver/remote/webelement.py", line 75, in click
    self._execute(Command.CLICK_ELEMENT)
  File "/home/mint/Python_Projects/venv/lib/python3.4/site-packages/selenium/webdriver/remote/webelement.py", line 469, in _execute
    return self._parent.execute(command, params)
  File "/home/mint/Python_Projects/venv/lib/python3.4/site-packages/selenium/webdriver/remote/webdriver.py", line 201, in execute
    self.error_handler.check_response(response)
  File "/home/mint/Python_Projects/venv/lib/python3.4/site-packages/selenium/webdriver/remote/errorhandler.py", line 194, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: Element is not clickable at point (61, 24.300003051757812). Other element would receive the click: <a class="navbar-brand" href="#"></a>

推荐答案

您的答案就在您的问题之内.

Your Answer lies within your question.

  1. 错误说'add_task_sidebar_link'在该位置不可点击-(61,24.300003051757812)这是另一个元素所在的地方-其他元​​素将获得点击:< a class ="navbar-品牌"href ="#></a> 尝试点击的位置.由于您没有使浏览器最大化,因此无法正确获取点坐标.
  2. 为了以后的测试不中断,请滚动到该元素.请参阅这篇文章( Selenium python无法向下滚动).检查操作链( http://selenium-python.readthedocs.org/api.html#module-selenium.webdriver.common.action_chains )
  1. Error says 'add_task_sidebar_link' not clickable at point - (61, 24.300003051757812) This is where another element is - Other element would receive the click: <a class="navbar-brand" href="#"></a> where the click is being attempted. Since you did not maximize the browser, you are not able to get the point co ordinates correctly.
  2. In order for future tests to not break, pls scroll to that element. Refer to this post (Selenium python unable to scroll down). Check Action chains (http://selenium-python.readthedocs.org/api.html#module-selenium.webdriver.common.action_chains)

这篇关于硒:元素不可点击...其他元素将获得点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 01:52