2013-10-24 180 views
0

我有一個帳號菜單。當我們將鼠標放在它上面時,它的子菜單出現在屏幕上。 截圖如下。MoveTargetOutOfBoundsException硒,蟒蛇

enter image description here

我想點擊帳戶Summary.My硒代碼如下。

def test_accounts(self): 
    self.login(self.driver,properties.userid,properties.password) 

    element_to_hover=self.driver.find_element_by_link_text('Accounts') 
    hover=ActionChains(self.driver).move_to_element(element_to_hover) 
    hover.click().perform() 
    self.driver.implicitly_wait(10) 
    self.driver.find_element_by_link_text('Account Summary').click() 

我收到以下錯誤消息。

test_accounts (__main__.TestCase) ... ERROR 

====================================================================== 
ERROR: test_accounts (__main__.TestCase) 
---------------------------------------------------------------------- 
Traceback (most recent call last): 
    File "C:\New Workspace\Python Test\src\login.py", line 78, in test_accounts 
    self.driver.find_element_by_link_text('Account Summary').click() 
    File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webelement.py", line 51, in click 
    self._execute(Command.CLICK_ELEMENT) 
    File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webelement.py", line 225, in _execute 
    return self._parent.execute(command, params) 
    File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 160, in execute 
    self.error_handler.check_response(response) 
    File "C:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 149, in check_response 
    raise exception_class(message, screen, stacktrace) 
MoveTargetOutOfBoundsException: Message: '' 

---------------------------------------------------------------------- 
Ran 1 test in 24.563s 

FAILED (errors=1) 

我在SO和其他人嘗試了很多鏈接,但無法找到我的問題的解決方案。 由於我是新手,以硒,這是正確的方法鼠標移到一個鏈接,並去其隱藏的子元素?

我使用Python 2.7。 任何幫助,將不勝感激

回答

0

我認爲事件的繼承應該是: 舉動元帳號 - >移動至元素帳戶總結 - >單擊元素 - >執行

2

這是你應該點擊的方式在元素上:

accounts_button = driver.find_element_by_link_text('Accounts') 

hidden_button = browser.find_element_by_id(hidden_button) 

ActionChains(driver).move_to_element(accounts_button).click(hidden_button).perform() 

所以,你可以看到,就是這樣,請刪除你的代碼的最後兩行。