3

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)
12
  • Most probably the id u_0_1h, is ever changing right? Commented Feb 12, 2018 at 7:01
  • Do you see exactly the same @id value after page refresh? Commented Feb 12, 2018 at 7:04
  • I would locate using reaction_profile_tab_count. Seems unique and stable Commented Feb 12, 2018 at 7:06
  • No, the id is still the same after refreshing the page. Commented Feb 12, 2018 at 7:06
  • How to use reaction_profile_tab_count? Commented Feb 12, 2018 at 7:07

1 Answer 1

3

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()
Sign up to request clarification or add additional context in comments.

3 Comments

Though a bit complicated, it works. Thank you very much. DebanjanB.
When I put class1 = "'10tn'", and replace '_10tn' by class1. It does not work. That is, WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='scrollAreaColumn' and starts-with(@id,'u_0')]/span[@class=class1]/span[@class='_5p-9 _5p-l' and contains(@aria-label,'Like')]//span[@data-sigil='reaction_profile_tab_count']"))).click()
See the application you are automating is based on ReactJS, hence the xpath was crafted considering a lot of pros & cons to cater to your specific need. I am not sure why you want to tweak the attributes. If your requirement have changed feel free to raise a new question. SO volunteers will be happy to help you out.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.