Я пытаюсь нажать кнопку «Загрузить еще» с помощью Selenium.Хотя я получаю ошибку Message: element not interactable
.Когда я сохраняю ответ HTML, загруженный Selenium и открывающийся как HTML, я вижу, что кнопка есть, и она доступна для нажатия (см. Изображение ниже).Также вот тег кнопки с этой сохраненной страницы:
<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 && !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 && !vm.hideIf" ng-click="vm.click()" style="">LOAD MORE</div>
<!-- end ngIf: vm.model.length && !vm.hideIf -->\n</div>\n</kcl-load-more>
Вот код, который я использую:
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()
Как мне нажать кнопку?
PS Полный журнал исключений:
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 && !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)