ElementNotVisibleException,是否有Selenium的解决方案?

时间:2016-05-26 13:56:49

标签: python html symfony selenium

我今天在我的网站测试时遇到一个奇怪的错误:

ElementNotVisibleException: Message: Element is not currently visible and so may not be interacted with

我想用selenium测试一些非常简单的东西,只是为了测试当我点击我的徽标时,我是否被重定向到了好的登陆页面。 我做了这个非常简单的代码:

@classmethod
def setUp(self):
    self.driver = webdriver.Firefox()
    self.driver.get('http://localhost')


def test_navigation_to_home_page(self):

    # Click on the logo and check landing page
    self.driver.find_element_by_xpath("/html/body/header/div[2]/div/div/div//a").click()
    self.assertEqual(self.driver.current_url, 'http://localhost/')

@classmethod
def tearDown(self):
    self.driver.quit()

当我执行此代码时,我有上述错误。我试着用一个简单的time.sleep等待页面加载,看看它是否有帮助,但没有任何改变。 您可能会看到" // a"在xpath表达式中。这不是一个错误,这是因为如果我写/ figure / a,我有一个NoSuchElementException。 我的代码包含我要点击的徽标如下:

pagelayout.html.twig:

{% block header %}
    {{ render(controller('MyBundle:PageLayout:getHeader',  {'active_page':activePage})) }}
{% endblock %}

header.html.twig:

<header id="header" class="header navbar-fixed-top">
{% include 'MyBundle:PageLayout:cookie_barre.html.twig'%}
{% include 'MyBundle:PageLayout:metabarre.html.twig'%}
<div class="header-bar container-fluid">
    <div class="row">
        <div class="container">
            <div class="row">
                <figure class="header-logo header-item col-xs-8 col-sm-3"><a href="page-home">{{ ez_render_field(header, 'fs_header_logo', {'parameters':{'class': 'img-responsive'} } ) }}</a></figure>
                {{ render(controller('MyBundle:PageLayout:getMainMenu',  {'active_page':activePage, 'header':header})) }}
            </div>
        </div>
    </div>
</div>

我在另一个应用程序上做了很多Selenium测试,并没有收到任何此类错误。是因为我使用ez平台作为我的照片的渲染?有没有办法来解决这个问题 ?无论如何,所有网站都运行良好,只需要自动化一些测试。

谢谢。

0 个答案:

没有答案