2016年8月31日 星期三

python3 selenium 移動滑鼠到 element 範例 (hover)

使用 selenium 時,有點要被 click 的元件,可能要先將滑鼠 hover 到某個元件上才會顯示出來
可以這樣寫:
假設我們要切換幣別為 USD 但該網站設計,必需先移動到 #currency 元件上  #usd 選項才會出現。

from selenium.webdriver.common.action_chains import ActionChains
eleCurrency = self.driver.find_element_by_css_selector("#currency")
eleUsd = self.driver.find_element_by_css_selector("#usd")
actHoverThenClick = ActionChains(seleniumDriverInstance)
actHoverThenClick.move_to_element(eleCurrency).move_to_element(eleUsd).click().perform()

沒有留言: