我想点击喜欢的数量。我试着用
driver.find_element_by_id('u_0_1h').click()
和
driver.find_element_by_xpath('//span[@class="_5p-9 _5p-l" and @id="u_0_1h"]')
然而,两者都给出错误:
no such element: Unable to locate element.
如何解决这个问题?
<div class="scrollAreaColumn" id="u_0_1f"><span class="_10tn"
data-store="{"reactionType":1}" data-sigil="reaction_profile_sigil">
<span aria-label="24K Like" class="_5p-9 _5p-l" role="button" id="u_0_1h">
<i class="_2ep2 img sp_so7iNrBRN80 sx_084697"></i>
<span data-sigil="reaction_profile_tab_count">24K</span></span></span>
<span class="_10tn" data-store="{"reactionType":7}"
data-sigil="reaction_profile_sigil"><span aria-label="2.9K Sad"
class="_5p-9 _5p-l" role="button" id="u_0_1i"><i class="_2ep2 img
sp_so7iNrBRN80 sx_50972c"></i><span data-
sigil="reaction_profile_tab_count">2.9K</span></span></span>
<div class="_10tl" style="background: rgb(88, 144, 255)
答案 0 :(得分:3)
要点击喜欢的数量,即 24K
,您可以使用以下代码行:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='scrollAreaColumn' and starts-with(@id,'u_0_')]/span[@class='_10tn']/span[@class='_5p-9 _5p-l' and contains(@aria-label,'Like')]//span[@data-sigil='reaction_profile_tab_count']"))).click()