How to use Selenium in Python Click on the link… here is a solution to the problem.
How to use Selenium in Python Click on the link
I want to like it. I tried to use it
driver.find_element_by_id('u_0_1h').click()
and
driver.find_element_by_xpath('//span[@class="_5p-9 _5p-l" and @id="u_0_1h"]')
However, both give an error :
no such element: Unable to locate element.
How to solve this problem?
<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)
Solution
To click on the number of likes, i.e. 24K
, you can use the following line of code:
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()