2016-08-25 59 views
1

我在Ubuntu可靠的本地virtualbox以及travis上的可信映像上拥有完全相同版本的硒(2.53.6)和firefox(43.0)。Selenium在本地工作,但无法点击Travis上的链接

的HTML代码是微不足道的

<div> 
    <a href="/"><i class="fa fa-close fa-2x" aria-hidden="true"></i><br>Close</a><br> 
</div> 

测试代码是微不足道的,以及

def test_start_stop_container(self): 
    driver = self.driver 
    driver.get(self.base_url + "/hub/login") 
    driver.find_element_by_id("username_input").clear() 
    driver.find_element_by_id("username_input").send_keys("test") 
    driver.find_element_by_id("password_input").clear() 
    driver.find_element_by_id("password_input").send_keys("test") 
    driver.find_element_by_id("login_submit").click() 
    driver.find_element_by_name("action").click() 
    self.wait_for(lambda: "noVNC" == driver.title) 
    driver.find_element_by_xpath("//i").click() # << this here. 
    self.wait_for(lambda: "noVNC" != driver.title) 
    driver.find_element_by_name("action").click() 
    driver.find_element_by_xpath("//i").click() 
    driver.find_element_by_xpath("(//button[@name='action'])[2]").click() 
    self.wait_for(
     lambda: "Start" == driver.find_element_by_name("action").text) 
    driver.find_element_by_id("logout").click() 

在这两种情况下,我使用的Xvfb,但仅限于特拉维斯点击不工作。没有例外发生。看起来好像操作没有执行。我使用一些ffmpeg魔术记录了Xvfb的会话,我看到的是链接以蓝色突出显示(这是悬停颜色),但不会单击该链接。

This video shows the exact operation (starts around 20 sec mark)

是否有人有问题可能是什么想法,或者有什么东西我可以做些什么来调试呢?

+0

你说的是这行'driver.find_element_by_xpath( “//我”)点击()'??。 –

+0

@SaurabhGaur是的。这实际上是一种选择。我也尝试在关闭标签上选择,但结果是一样的。 –

+0

您是否尝试过使用'driver.find_element_by_link_text(“Close”)。click()'或'driver.find_element_by_partial_link_text(“Close”)。click()'??? –

回答

1

其实如预期的WebElement一段时间click()方法不起作用由于元素或其他问题的一些设计问题。因此,在这种情况下,这是由硒提供的替代解决方案,用于执行一块JavaScript以对元素执行更多事件。

所以可以使用execute_script(),而不是执行点击这里如下: -

driver.execute_script("arguments[0].click()", driver.find_element_by_link_text("Close")) 
0

试试这个XPath来识别HREF - "//a[contains(text(),'Close')]"