1

I would like to click on load more button to show all 347 products, however it returns Message: element not interactable, any idea how can i fix it?

load more button

from selenium import webdriver
driver=webdriver.Chrome('e:/Users/fungc1/Documents/chromedriver.exe')
from selenium.webdriver.chrome.options import Options
import time
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
options=Options()


url= "https://www.toysrus.com.sg/lego"
driver.get(url)

while True:
    try:
                                        
        btn = driver.find_element_by_xpath("//*[name()='use' and @*='#chevron-circle-thin']")
        btn.click()
    except Exception as e:
        print(e)
        break
6
  • You are grabbing a tag inside the <svg> tag which is the button picture. What you need to click is the <button> tag that contains the <svg>. Commented May 17, 2021 at 4:50
  • Do you really need Selenium for this? The <button> tag for the next page just fires a single URL. You could do another request for that. Commented May 17, 2021 at 4:52
  • change your xpath to this - //div[@class='show-more']/button Commented May 17, 2021 at 5:14
  • When i change the xpath to be //div[@class='show-more']/button , it says element not interactable Commented May 17, 2021 at 5:28
  • Message: element click intercepted: Element <button class="btn" data-url="toysrus.com.sg/on/demandware.store/Sites-ToysRUs_SG-Site/en_SG/…> is not clickable at point (508, 657). Other element would receive the click: <div class="inner">...</div> (Session info: chrome=90.0.4430.212) Commented May 17, 2021 at 5:46

2 Answers 2

1

The thing is you would need to scroll till end of page to let selenium know where is the button in view point.

Code :

driver.get("https://www.toysrus.com.sg/lego/")
sleep(5)
driver.execute_script("var scrollingElement = (document.scrollingElement || document.body);scrollingElement.scrollTop = scrollingElement.scrollHeight;")
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button.btn[data-url*='www.toysrus.com']"))).click()
print("Clicked on ")

Update 1 :

driver = webdriver.Chrome("C:\\Users\\***\\Desktop\\Selenium+Python\\chromedriver.exe")
driver.maximize_window()
wait = WebDriverWait(driver, 30)
driver.get("https://www.toysrus.com.sg/lego/")

while True:
    try:
        sleep(5)
        driver.execute_script("var scrollingElement = (document.scrollingElement || document.body);scrollingElement.scrollTop = scrollingElement.scrollHeight;")
        sleep(5)
        wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button.btn[data-url*='www.toysrus.com']"))).click()
        print("Clicked on ")
    except Exception as e:
        print(e)
Sign up to request clarification or add additional context in comments.

11 Comments

Message: element click intercepted: Element <button class="btn" data-url="toysrus.com.sg/on/demandware.store/Sites-ToysRUs_SG-Site/en_SG/…> is not clickable at point (509, 124). Other element would receive the click: <div class="modal country-switcher show" data-popup-country-selector="" data-write-country-to-cookie="SG" tabindex="-1" role="dialog" id="country-switcher-modal" aria-modal="true" style="padding-right: 16px; display: block;">...</div>
Well it works perfectly fine in my machine. "C:\Program Files\Python39\python.exe" C:/Users/etc/PycharmProjects/SeleniumSO/SOProblems.py Clicked on Process finished with exit code 0
Did you remove the sleep ?
pasteboard.co/K2gzoLh.jpg my screen capture here
pasteboard.co/K2gBxB3.jpg the error is: Message: element click intercepted: Element <button class="btn" data-url="toysrus.com.sg/on/demandware.store/Sites-ToysRUs_SG-Site/en_SG/…> is not clickable at point (509, 124). Other element would receive the click: <div class="modal country-switcher show" data-popup-country-selector="" data-write-country-to-cookie="SG" tabindex="-1" role="dialog" id="country-switcher-modal" aria-modal="true" style="padding-right: 16px; display: block;">...</div>
|
0
wait=WebDriverWait(driver, 10)

url= "https://www.toysrus.com.sg/lego"
driver.get(url)
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR,".affirm.btn.btn-outline-secondary"))).click()
while True:
    try:
        wait.until(EC.element_to_be_clickable((By.XPATH,"//div[@class='show-more']/button"))).click()
        time.sleep(5)
    except Exception as e:
        print(e)
        break

You should replace time.sleep() for the visibility of the spinner. But just wait for the elements to load in.

allProducts=driver.find_elements_by_xpath("//div[@class='product-grid-wrapper']//div[@class='card product-tile product']")
print(len(allProducts))

Prints 346?

7 Comments

pasteboard.co/K2hb0c9.jpg Can you take a look why 96/346 product printed, not 346/346 ?
You grabbed the values prior to show more.
i dont understand your answer, somehow i found the reason why it shows 96 product, it is because even the button is clicked for a few times, the view-source:toysrus.com.sg/lego will only have the first 96 product, do you know how can i fix it
I don't see where your grabbing the values after the button click.
it starts from : for item in toc: can you go to the following link to view my notebook in anaconda drive.google.com/file/d/1EeZ1_mWHHh49m48Tmj1ffZAIdYc9b4wJ/…
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.