To click on the element with text as Show 10 more deals on the page https://www.uswitch.com/broadband/compare/deals_and_offers/
you can use the following solution:
-
Code Block:
from selenium import webdriver from selenium.webdriver.support.wait import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.common.by import By url = "https://www.uswitch.com/broadband/compare/deals_and_offers/" options = webdriver.ChromeOptions() options.add_argument("start-maximized") options.add_argument('disable-infobars') browser = webdriver.Chrome(chrome_options=options, executable_path=r'C:\Utility\BrowserDrivers\chromedriver.exe') browser.get(url) while True: try: browser.execute_script("return arguments[0].scrollIntoView(true);", WebDriverWait(browser,20).until(EC.visibility_of_element_located((By.XPATH, "//button[@class="us-btn us-btn--action" and contains(.,'Show 10 more deals')]")))) browser.execute_script("arguments[0].click();", WebDriverWait(browser,20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button.us-btn.us-btn--action[name="visible_products"]")))) print("Button clicked") except: print("No more Buttons") break browser.quit()
-
Console Output:
Button clicked Button clicked Button clicked Button clicked Button clicked Button clicked Button clicked Button clicked Button clicked Button clicked No more Buttons
2
solved Click on “Show more deals” in webpage with Selenium