how to click mouse over sub menu in selenium?

2019-09-11 04:04发布

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

*invisible html source

enter image description here

<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条回答
何必那么认真
2楼-- · 2019-09-11 05:09

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()
查看更多
登录 后发表回答