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 badges1 Answer
Reset to default 0Refer 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
版权声明:本文标题:Python Selenium clicking a jquery dropdown to expose more dropdowns - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743934391a2564425.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论