how to click mouse over sub menu in selenium?

这一生的挚爱 提交于 2019-12-25 07:50:00

问题


I want to click invisible html's sub menu click.

*invisible html source

<ul class="options">
<li class="_ranking-attr-filter-container _sub-menu-target">
<span>Hide work using these filters</span>
</li></ul>

*my code

element_to_hover_over = _Driver.find_element_by_xpath("//li[contains(@class, 'sub-menu-target')]")
hover = ActionChains(_Driver).move_to_element(element_to_hover_over).perform()
wait.until(EC.presence_of_element_located((By.PARTIAL_LINK_TEXT, unicode("男", errors='replace')))).click()  #this line don't working. 10061 socket error.

my code's mouse hover part is working, but sub menu's click don't working. but sub menu's kanji is invisible in html(can't find id, class name), I don't know how to select sub menu.

I tried this, but don't work(UnicodeDecodeError: 'utf8' codec can't decode blarblar...)

wait.until(EC.presence_of_element_located((By.XPATH, '//input[@type="checkbox"][contains(text(), "男")]'))).click()

I need your advise, thank you.


回答1:


Search by PARTIAL_LINK_TEXT as well as search by LINK_TEXT is used for anchor tags only (<a>), so you might try to use

wait.until(EC.presence_of_element_located((By.XPATH, '//input[@type="checkbox"][contains(text(), "男")]'))).click()


来源:https://stackoverflow.com/questions/41795013/how-to-click-mouse-over-sub-menu-in-selenium

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!