admin管理员组

文章数量:1353597

I'm new to Selenium and trying to undertake a live example of web-scraping a list using the following URL - /

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.webdrivermon.by import By
import time
from selenium.webdrivermon.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('/')

# 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

I'm new to Selenium and trying to undertake a live example of web-scraping a list using the following URL - https://mcscertified/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.webdrivermon.by import By
import time
from selenium.webdrivermon.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/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

Share Improve this question asked Mar 31 at 16:32 Lee MurrayLee Murray 5111 gold badge7 silver badges21 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 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/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()

本文标签: Python Selenium clicking a jquery dropdown to expose more dropdownsStack Overflow