Frankie
Frankie

Reputation: 784

How to use Selenium to click on the link in Python

I want to click on the number of likes. I tried to use

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 the 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="{&quot;reactionType&quot;: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="{&quot;reactionType&quot;: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)

Upvotes: 3

Views: 291

Answers (1)

undetected Selenium
undetected Selenium

Reputation: 193058

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()

Upvotes: 3

Related Questions