這幾天的自動化測試過程中遇到一些自定義的下拉框列表,這種下拉列表沒有關鍵字select,所以想要選擇下拉列表中的值,只能是去點擊了,然而在點擊的過程中老遇到錯誤,其中有 can not visiable,有element is not clickable at point的錯誤
其實selenium2library 中有一個方法focus,但是個人認為不是很好用,因為也會經常的提示不可點擊,所以我稍微改變了一下,新建了自己定義的一個方法 find_element()代碼如下:
deffind_element(self, locator):
"""Sets element identified by `locator` as current frame.
can find element in your page or out of your page
"""
self._info("find_element '%s'."% locator)
element =self._element_find(locator,True,True)
self._current_browser().switch_to_active_element()
self._current_browser().execute_script("return arguments[0].scrollIntoView();", element)
比focus多了一行代碼self._current_browser().switch_to_active_element()
就是說我先找到某個元素,然后切換到那個元素中去,