Element is not clickable issue on chrome

這陣子將SeleniumLibrary升級至3.0之後,在Firefox上測試遇到難以解決的問題,也因此將測試瀏覽器改為Chrome;然而移到chrome之後,原先可以在firefox上執行的測試,反而變得無法執行。其中一樣就是出現Element is not clickable的問題。

我要點擊的位置是Refresh的button:

而我一開始使用的xpath是

//span[text()='Refresh']

但卻出現了以下錯誤訊息:
WebDriverException: Message: unknown error: Element <span class="ui-button-text">...</span> is not clickable at point (805, 96). Other element would receive the click: <span class="ui-button-icon-primary ui-icon ui-icon-refresh"></span>
  (Session info: chrome=63.0.3239.132)
  (Driver info: chromedriver=2.34.522940 (1a76f96f66e3ca7b8e57d503b4dd3bccfba87af1),platform=Windows NT 6.3.9600 x86_64)
後來從此篇文章得知,ChromeDriver使用模擬方式去點element中間的位置;假如你所給予的位置是使用者點不到的位置,就有可能會發生這樣的問題。

舉例來說,使用一個modal dialog會讓背景呈現蓋住的效果;對使用者來說,背景是無法點擊的。假如這時候透過ChromeDriver去點擊背景的element,就會發生無法點擊的問題。

以我的問題來說,將xpath改為圖片或button的xpath即可解決。

因此,Click Element的xpath最好是設定為使用者一定可以點擊的到的位置。