-1

I'm trying to automate the clicking of the "SHOW MORE" button at the bottom of the page to get all the reviews there is.

However, I'm having some problems locating it and would really appreciate it if you could help me out.

I have tried a couple of methods but I am not sure why none of them work.

1) Method 1: CSS Selector

driver.find_element_by_css_selector("U26fgb.O0WRkf.oG5Srb.C0oVfc.n9lfJ.M9Bg4d")

leads to:

NoSuchElementException: Message: no such element: Unable to locate element

2) Method 2 : XPath Helper (an extension on Chrome)

driver.find_element_by_xpath("/html/body[@id='yDmH0d']/div[@id='fcxH9b']/div[@class='WpDbMd']/c-wiz[@class='zQTmif SSPGKf I3xX3c drrice']/div[@class='T4LgNb']/div[@class='ZfcPIb']/div[@class='UTg3hd']/div[@class='JNury Ekdcne']/div[@class='LXrl4c']/div/div[@class='W4P4ne ']/div[2]/div[@class='PFAhAf']/div[@class='U26fgb O0WRkf oG5Srb C0oVfc n9lfJ']/span[@class='CwaK9']/span[@class='RveJvd snByac']")

leads to the same error as above.

3) Method 3 : WebDriverWait

I read the other stack overflow questions related to this and tried using WebDriverWait and here is my code:

WebDriverWait(driver, 15).until(EC.presence_of_element_located((By.XPATH, "/html/body[@id='yDmH0d']/div[@id='fcxH9b']/div[@class='WpDbMd']/c-wiz[@class='zQTmif SSPGKf  I3xX3c drrice']/div[@class='T4LgNb']/div[@class='ZfcPIb']/div[@class='UTg3hd']/div[@class='JNury Ekdcne']/div[@class='LXrl4c']/div/div[@class='W4P4ne ']/div[2]/div[@class='zc7KVe']/div[@class='d15Mdf bAhLNe']/div[@class='xKpxId zc7KVe']/div[@class='bAhLNe kx8XBd']/span[@class='X43Kjb']"))).click()

but was faced with TimeoutException

4) I came across another question on changing frames when faced with such errors but it seems like I don't have a frame to switch to (Do correct me if I'm wrong)

This is the url of the page: https://play.google.com/store/apps/details?id=com.Daylight.EzLinkAndroid&hl=en_SG

The HTML that I have problems with is as follows:

<div class="PFAhAf" jscontroller="XO1Ihd" jsaction="JIbuQc:bRsdTc(i3y3Ic);">
      <div role="button" class="U26fgb O0WRkf oG5Srb C0oVfc n9lfJ M9Bg4d 
         j7nIZb" jscontroller="VXdfxd" jsaction="click:cOuCgd; 
         mousedown:UX7yZ; mouseup:lbsD7e; mouseenter:tfO1Yc; 
         mouseleave:JywGue; focus:AHmuwe; blur:O22p3e; 
         contextmenu:mg9Pef;touchstart:p6p2H; touchmove:FwuNnf; 
         touchend:yfqBxc(preventMouseEvents=true|preventDefault=true); 
         touchcancel:JMtRjd;j9grLe:.CLIENT;HUObcd:.CLIENT" jsshadow="" 
         jsname="i3y3Ic" aria-disabled="false" tabindex="0">
               <div class="Vwe4Vb MbhUzd" jsname="ksKsZd" style="top: 17.2px; 
                     left: 70.225px; width: 98px; height: 98px;"></div>
               <div class="ZFr60d CeoRYc"></div><span jsslot="" class="CwaK9"> 
             <span class="RveJvd snByac">Show more</span>
             </span>
      </div>
</div>

Sorry for the long post and thank you for your help! :)

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
shannonk
  • 3
  • 2
  • The link you have shared doesn't have any element with text Show more. Make sure that the element is present on the page. – S Ahmed Jun 11 '19 at 07:02
  • Sorry for the inconvenience. Scroll to the bottom of this link until you see the "SHOW MORE" button. https://play.google.com/store/apps/details?id=com.Daylight.EzLinkAndroid&hl=en_SG&showAllReviews=true – shannonk Jun 12 '19 at 01:18

2 Answers2

1

Your yDmH0d, fcxH9b, etc. seems to be dynamically generated and change each time you load/reload the page. The only thing which doesn't change is span tag text.

So I would recommend using the following simple selector:

WebDriverWait(driver, 15).until(EC.presence_of_element_located((By.XPATH, "//span[text()='Show more']"))).click()

enter image description here

Also consider using Page Object Model design pattern, it will make your life easier when it comes to test support when/where UI changes and lets you write tests much faster.

See Page Objects page of Selenium Python documentation for more information if needed.

Dmitri T
  • 159,985
  • 5
  • 83
  • 133
  • Thank you so much for your help!! It worked :) As i am still pretty new to this, may i know how you realize that yDmH0d, fcxH9b, are dynamically generated? – shannonk Jun 12 '19 at 01:24
  • Also, i initially thought that clicking of the button would involve the
    – shannonk Jun 12 '19 at 01:28
0

As the element is JavaScript enabled element so to click() it you need to induce WebDriverWait for the element_to_be_clickable() and you can use the following Locator Strategy:

  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@role='button']//span/span[text()='Show more']"))).click()
    
  • Note : You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Hi! Thank you for your help but I seem to face the following error when running your code: ElementClickInterceptedException: Message: element click intercepted: Element ... is not clickable at point (611, 10). – shannonk Jun 12 '19 at 01:25