1

I'm new to Selenium and trying to undertake a live example of web-scraping a list using the following URL - https://mcscertified.com/find-an-installer/

However, I'm struggling to click on a drop-drown 'What would you like to install?' to expose more check boxes, 'Solar PV'.

Below is my work in progress code which works, except for the 'What would you like to install?' drop-down.

Would love any advice or pointers. I have commented out my code that does not work.

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

opts = webdriver.FirefoxOptions()
serv = webdriver.FirefoxService( executable_path='/snap/bin/geckodriver' )

driver = webdriver.Firefox( options=opts, service=serv )  
driver.get('https://mcscertified.com/find-an-installer/')

# Delay to let page load
time.sleep(5)


# click allow button
btn_allow = driver.find_element(By.ID,"CybotCookiebotDialogBodyLevelButtonLevelOptinAllowAll")
btn_allow.click()

# click 'What would you like installed? 
# WebDriverWait(driver, 5).until(EC.element_to_be_clickable((By.XPATH, "//span[normalize-space()='msw-arrow']"))).click()
# WebDriverWait(driver, 5).until(EC.element_to_be_clickable((By.XPATH, "//label[contains(., 'msw-arrow')]"))).click()

# click Solar PV checkbox
WebDriverWait(driver, 5).until(EC.element_to_be_clickable((By.XPATH, "//label[contains(., 'Solar PV')]"))).click()

# click 'What would you like All of UK?'
WebDriverWait(driver, 5).until(EC.element_to_be_clickable((By.XPATH, "//label[contains(., 'All of the UK')]"))).click()

btn_allow = driver.find_element(By.ID, "msw-installer-launchpad-search-installers-tech-type")
btn_allow.click()

I'll add in the HTML once I understand it from the source:-

Many thanks

1 Answer 1

0

Refer the working code below:

What would you like to install? - Interacting with this element is tricky. I tried Selenium's Explicit Waits it didn't work. However I managed to interact with it using JS.

driver = webdriver.Firefox()
driver.get('https://mcscertified.com/find-an-installer/')
driver.maximize_window()

wait = WebDriverWait(driver, 10)
wait.until(EC.element_to_be_clickable((By.ID, "CybotCookiebotDialogBodyLevelButtonLevelOptinAllowAll"))).click()

# click 'What would you like installed?
dropdown = wait.until(EC.visibility_of_element_located((By.XPATH, "//span[@class='msw-arrow down']")))
driver.execute_script("arguments[0].click();",dropdown)

# click Solar PV checkbox
wait.until(EC.element_to_be_clickable((By.XPATH, "//input[@id='msw-installer-launchpad-tech-type-spv']//parent::label"))).click()

# click on the checkbox 'All of the UK'
wait.until(EC.element_to_be_clickable((By.XPATH, "//input[@id='msw-installer-launchpad-region-uk']//parent::label"))).click()

# Click on Search button
wait.until(EC.presence_of_element_located((By.ID, "msw-installer-launchpad-search-installers-tech-type"))).click()
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.