0

I am trying to click on "Load More" on a page using selenium. I used the below css_selector code :

element= driver.find_element_by_css_selector('#amscroll-page-2]')
driver.execute_script("arguments[0].scrollIntoView(true);", element)

I am getting the following error.

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".amscroll-load-button"}
  (Session info: chrome=83.0.4103.61)

and I used xpath code:

elemnent=driver.find_element_by_xpath('//*[@id="amscroll-page-2"]')
driver.execute_script("arguments[0].scrollIntoView();", element)
time.sleep(5)
login=element.click()

i am getting the following error

raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element <div class="amscroll-page loading" id="amscroll-page-2" rel="2">...</div> is not clickable at point (382, 18). Other element would receive the click: <div class="naaod__content">...</div>
  (Session info: chrome=83.0.4103.61)

The html code of where till where i want to scroll down and click is :

    <div class="amscroll-page loading" id="amscroll-page-2" rel="2"><input type="button" 
class="amscroll-load-button" style="background: #2675C2;" onclick="amscroll_object.loadNextPage(2);" value="Load More"></div>

There is a load more button over here which i want to click on using selenium.

1
  • There is some scroll logic that requires you to scroll for the button to appear. I have a working script, however, if you read the Terms of service of the page you're scraping, you will realize that scraping is prohibited. I will therefore not provide the answer. Commented Jul 12, 2020 at 17:38

2 Answers 2

2

To do that you should use the click() function from the selenium module. We will find the button by a CSS selector - this will decrease the chances that the wrong element will be clicked

self.webdriver.find_element_by_css_selector('input[class="amscroll-load-button"]').click()

However, I would recommend using that code

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

WebDriverWait(self.webdriver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, 'input[class="amscroll-load-button"]'))).click()

This code checks for the button to be clickable X seconds, and if it does it will be clicked.

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

21 Comments

driver.webdriver.find_element_by_css_selector('input[c lass="amscroll-load-button"]').click() AttributeError: 'WebDriver' object has no attribute 'webdr iver' I am getting this error.
when I use the second code I am getting this error: NameError: name 'self' is not defined
@raptorzee you have to replace the self.webdriver with the name of your webdriver instance.
no mate. now I am getting this error.raise exception_class(message, screen, stacktrace) selenium.common.exceptions.InvalidSelectorException: Message: invalid selector: An invalid or illegal selector was specified (Session info: chrome=83.0.4103.61)
@raptorzee driver.find_element_by_css_selector('input[class="amscroll-load-button"]').click() are you sure that you call the exact command?
|
1

I was able to solve this by using the following code:

button = driver.find_element_by_xpath("/html/body/div[3]/div/div[1]/div[2]/div[2]/div[2]/div[3]/div[1]")
ActionChains(driver).move_to_element(button).click(button).perform()

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.