2016-07-15 97 views
1

嗨我試圖點擊這個按鈕,保持禁用,直到你填寫其他領域。我正在使用Firefox。我的腳本填寫了這些字段,現在可以用鼠標點擊按鈕。但是當我嘗試通過硒單擊該元素時,出現錯誤硒灰色按鈕

WebDriverException: Message: Element is not clickable at point (281.8333282470703, 14.149993896484375). Other element would receive the click: <li ng-class="{active: $state.includes('urlAdm')}" id="adm-menu"></li>  

這裏是按鈕的html。

<div class="col-xs-offset-2 col-xs-5"> 
    <button type="submit" class="btn btn-primary ng-binding" ng-disabled="!userForm.$valid || user.deleted_at" disabled="disabled"> 
     <i class="fa fa-check-square-o fa-fw"></i> 
     Create 
    </button> 
    <!-- ngIf: isAddUser() --><button ng-if="isAddUser()" type="button" class="btn btn-default ng-scope" ng-click="resetForm()"> 
     <i class="fa fa-eraser fa-fw"></i> 
     Clear 
    </button><!-- end ngIf: isAddUser() --> 
    <!-- ngIf: !user.deleted_at && user.id !== currentUser.id && user.id --> 
    <!-- ngIf: user.deleted_at --> 
    </div> 

我已經試過定期點擊按鈕,並通過行動做到這一點,但都沒有工作。

下面是代碼

element = driver.find_element_by_xpath("//*[@id='user-editor-1']/form/div[5]/div/button[1]") 
    ActionChains(driver).move_to_element(element).click().perform() 

任何幫助將不勝感激。謝謝!

+0

如果你看一下錯誤信息,你會看到什麼元素被阻斷單擊。那是什麼元素?它是一個彈出窗口或者你可以忽略的東西嗎? – JeffC

+0

當我看着屏幕時,我沒有看到任何覆蓋按鈕。我可以用鼠標點擊它,所以我假設沒有任何東西可以覆蓋它。這是一個有效的假設嗎? –

+0

如果不親自看,很難說。有時候,如果腳本速度足夠快,並且站點需要幾分之一秒來隱藏彈出窗口等,腳本可能會看到某些內容阻止了該元素,但您可能只會看到一個Flash。在得到錯誤之前,我會在行上放置一個斷點並查看發生了什麼。你可能會看到它更好。 – JeffC

回答

0

你應該嘗試click如下使用execute_script(): -

element = driver.find_element_by_xpath("//button[contains(.,'Create')]") 

driver.execute_script("arguments[0].click();",element) 

希望它能幫助.... :)

+0

高你能解釋一下我這是什麼嗎? –

+0

@JohnDoe它會點擊你想要的元素使用javascript –

+1

@JohnDoe只是讓你知道...使用'execute_script()'執行一個用戶無法執行的動作。 Selenium被設計爲不能與隱藏元素交互,因爲其意圖是僅允許用戶場景,例如,用戶不能點擊隱藏或禁用的按鈕。 JS會允許你這樣做,但這顯然不再是用戶場景。如果你確定,那很好......我只是想讓你知道,如果你還沒有。 – JeffC