Reputation: 11
I'm new in Webscraping, I want to click this button "Afficher plus" which has the HTML code below.
<button class="more-results js-more-results" id="search-more-results">Afficher plus de résultats</button>
I tried the code below in selenium but it doesn't click the button.
driver = webdriver.Safari()
driver.get(carte)
bt = driver.find_element_by_id("search-more-results")
bt.click()
"carte" is the link the of web page I want to scrape.
Upvotes: 1
Views: 5805
Reputation: 4212
1 Check if this button is not inside an iframe.
2 If not, try waiting until this button is clickable
3 '"carte" is the link the of web page I wanna to scrape.' You are using get() function incorrectly. It is used to open a page, not to get a link from a page.
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
driver = webdriver.Safari()
driver.get("YOUR WEB PAGE")
wait = WebDriverWait(driver, 30)
wait.until(EC.element_to_be_clickable((By.ID, "search-more-results")))
bt = driver.find_element_by_id("search-more-results")
bt.click()
If this won't work, try CSS selector or XPath. Example for CSS:
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "#search-more-results")))
email = driver.find_element_by_css_selector('#search-more-results').click()
Upvotes: 1