Home > Enterprise >  Python Selenium: How to select dropdown menu
Python Selenium: How to select dropdown menu

Time:12-30

enter image description hereI need to select the item - "Property owner statement" in dropdown menu. In the screenshot, it shows there has no unique name I can select on the ul class so the code doesn't works.

[![from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

url = 'https://system.arthuronline.co.uk/genieliew1/dashboards/index'
driver.get(url)
wait = WebDriverWait(driver, 20)

titleTags=driver.find_elements(By.CLASS_NAME, "select2-result")
select.selectByVisibleText("Property Owner Statement")][1]][1]

CodePudding user response:

Try this.

    titleTags = driver.find_element(By.CLASS_NAME, "select2-result")

    # select the title dropdown
    select_titleTags = Select(titleTags)
    select.selectByVisibleText("Property Owner Statement")][1]][1]

CodePudding user response:

The drop-down is not a select type class. You can't use selenium select class.

You need to click on the dropdown element first and then click on specific element listed. Use WebDriverWait() and wait for element to be clickable.

url = 'https://system.arthuronline.co.uk/genieliew1/dashboards/index'
driver.get(url)
WebDriverWait(driver,20).until(EC.element_to_be_clickable((By.XPATH,"//div[@id='select2-drop']"))).click()
WebDriverWait(driver,20).until(EC.element_to_be_clickable((By.XPATH,"//div[contains(.,'Property Owner Statement')]"))).click()
  • Related