1

I am trying to click Load More button with Selenium. Though I'm getting the Message: element not interactable error. When I save the HTML response loaded by Selenium and open in as HTML I see the button is there and it is clickable ( see image below). Also here is a button tag from this saved page:

<kcl-load-more main-class="mb-25" on-click="addMorePosts()" model="latestPosts" model-loading="postsLoading" class="ng-isolate-scope">
<div class="kcl-load-more mb-25" ng-class="vm.mainClass">\n\n
    <!-- ngIf: vm.model.length && !vm.hideIf -->
    <button class="kcl-btn ng-scope" ng-class="vm.buttonClass" ng-click="vm.click()" ng-disabled="vm.loading || vm.modelLoading" ng-if="vm.model.length &amp;&amp; !vm.hideIf" style="">\n <span class="hidden-side-scroll">LOAD MORE</span>\n
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 35.09 34.39" height="32" width="32" aria-labelledby="title" class="icon visible-side-scroll">\n
            <title>Load More</title>\n
            <path fill="#3B3B3B" d="M35.09,17.19s0-.09,0-.13h0a1.31,1.31,0,0,0-.38-.78l0,0L18.82.38A1.31,1.31,0,0,0,17,2.23L30.62,15.88H1.31a1.31,1.31,0,0,0,0,2.62H30.62L17,32.15A1.31,1.31,0,1,0,18.82,34L34.67,18.15l0,0a1.31,1.31,0,0,0,.38-.79h0s0-.09,0-.14Z"></path>\n </svg>\n </button>
    <!-- end ngIf: vm.model.length && !vm.hideIf -->\n
    <!-- ngIf: vm.model.length && !vm.hideIf -->
    <div class="visible-side-scroll text-center ng-scope" ng-if="vm.model.length &amp;&amp; !vm.hideIf" ng-click="vm.click()" style="">LOAD MORE</div>
    <!-- end ngIf: vm.model.length && !vm.hideIf -->\n</div>\n</kcl-load-more>

enter image description here

Here is the code I use:

from selenium import webdriver      
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
from selenium.webdriver.chrome.options import Options

URL = "https://thekrazycouponlady.com/coupons-for/costco"
LOAD_MORE_BUTTON_XPATH = '//button[@class = "kcl-btn ng-scope"]' 
# ADD_XPATH = '//button[@class = "btn btn-dismiss holiday-dismiss"]'
options = Options()
options.headless = True
driver = webdriver.Chrome(r'C:\Python3\selenium\webdriver\chromedriver_win32\chromedriver.exe', chrome_options=options)
driver.get(URL)

while True:
    try:
        time.sleep(35)
        html = driver.page_source.encode('utf-8')
        print(html)

        loadMoreButton = driver.find_element_by_xpath(LOAD_MORE_BUTTON_XPATH)
        loadMoreButton.click()

    except Exception as e:
        print (e)
        break
print ("Complete")

driver.quit()

How do I click the button?

P.S. Full exception log:

Traceback (most recent call last):
  File "C:\Code\Active\driverv1.py", line 10, in <module>
    wd.find_element_by_css_selector("button[ng-class='vm.buttonClass']").click()
  File "C:\Python3\lib\site-packages\selenium\webdriver\remote\webelement.py", line 80, in click
    self._execute(Command.CLICK_ELEMENT)
  File "C:\Python3\lib\site-packages\selenium\webdriver\remote\webelement.py", line 633, in _execute
    return self._parent.execute(command, params)
  File "C:\Python3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "C:\Python3\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Element <button class="kcl-btn ng-scope" ng-class="vm.buttonClass" ng-click="vm.click()" ng-disabled="vm.loading || vm.modelLoading" ng-if="vm.model.length &amp;&amp; !vm.hideIf" style="">...</button> is not clickable at point (511, 686). Other element would receive the click: <iframe id="google_ads_iframe_/4916285/sdb_tabbot_728x90.01_0" title="3rd party ad content" name="google_ads_iframe_/4916285/sdb_tabbot_728x90.01_0" width="728" height="90" scrolling="no" marginwidth="0" marginheight="0" frameborder="0" srcdoc="" style="border: 0px; vertical-align: bottom;" data-google-container-id="1" data-load-complete="true"></iframe>
  (Session info: chrome=70.0.3538.110)
  (Driver info: chromedriver=2.44.609538 (b655c5a60b0b544917107a59d4153d4bf78e1b90),platform=Windows NT 6.1.7601 SP1 x86)
12
  • @DebanjanB This is different question. The question you refer to is different one and it was answered. You did not show enough attention on that question posting irrelevant comment and now you close this question as duplicate. Please Undo. Commented Dec 10, 2018 at 15:55
  • Try using find_element_by_css_selector. This will work for you. from selenium import webdriver[new line] wd = webdriver.Chrome(chrome_path)[new line] URL = "thekrazycouponlady.com/coupons-for/costco"[new line] wd.get(URL)[new line] wd.find_element_by_css_selector("button[ng-class='vm.buttonClass']").click()[new line] Commented Dec 10, 2018 at 16:01
  • @HimanshuPoddar This did not help. Getting the very same error message. Commented Dec 10, 2018 at 16:06
  • @HimanshuPoddar I commented on his decision above. To no avile. Commented Dec 10, 2018 at 16:26
  • @BillyJhon , add full exception log. Also check whether print(len(driver.find_elements_by_xpath(LOAD_MORE_BUTTON_XPATH))) returns 1 Commented Dec 10, 2018 at 16:26

1 Answer 1

2

The page is too heavy and takes too much time to load. I have tried writing an optimal code for your problem.

from selenium import webdriver
URL = "https://thekrazycouponlady.com/coupons-for/costco"
chrome_path = r"chromedriver.exe"
wd = webdriver.Chrome(chrome_path)
wd.get(URL)

Wait until the pop up appears and when it does close it. You can also first try to scrape the contents and meanwhile if pop up appears close it but that will become a little bit complicated.

while(True):
    try:
        wd.find_element_by_css_selector("button[class='btn btn-dismiss holiday-dismiss']").click()
        break
    except:
        continue

Execute these three lines in a loop for loading the "LOAD MORE" contents, give delay of atmost 2s for each execution.

element = wd.find_element_by_css_selector("div[class='newsletter-sign-up-widget']")
element.location_once_scrolled_into_view
wd.find_element_by_css_selector("button[ng-class='vm.buttonClass']").click()

P.S : I have also tried it using headless chrome on google-colab. Comment below if you need the notebook for headless one on cloud.

Sign up to request clarification or add additional context in comments.

Comments

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.