Python селен выбрать вариант из выпадающего - PullRequest
0 голосов
/ 13 апреля 2019

Я пытаюсь выбрать опцию из http://www.lacoteargus.ma/cote-maroc/recherche/Но я получаю эту ошибку:selenium.common.exceptions.ElementNotVisibleException: Message: element not interactable: Element is not currently visible and may not be manipulatedв этой строкеBrands.select_by_visible_text('BMW')

Вот мой сценарий:

from selenium.webdriver.support.ui import Select
from selenium.webdriver.chrome.options import Options
import os
import time

Email = '***************'
Pass = '******'
LoginUrl = 'http://www.lacoteargus.ma/'

chrome_options = Options()
chromedriver_path = os.path.join(os.getcwd(), "chromedriver")
driver = webdriver.Chrome(executable_path=chromedriver_path, options=chrome_options)

driver.get(LoginUrl)
driver.find_element_by_name('strLogin').send_keys(Email)
driver.find_element_by_name('strPwd').send_keys(Pass)
driver.find_element_by_id('validation').click()
time.sleep(10)
driver.find_element_by_class_name('caret').click()
time.sleep(1)

Brands = Select(driver.find_element_by_id('marque'))
Brands.select_by_visible_text('BMW')

Я также пробовал:Brands.select_by_value('1')а такжеBrands.select_by_index('1')Никто из них не работает.

Ответы [ 2 ]

2 голосов
/ 13 апреля 2019

Это не элемент выбора, элемент выбора скрыт.

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import os

Email = '*****************'
Pass = '******'
LoginUrl = 'http://www.lacoteargus.ma/'

chrome_options = Options()
chromedriver_path = os.path.join(os.getcwd(), "chromedriver")
driver = webdriver.Chrome(executable_path=chromedriver_path, options=chrome_options)

driver.get(LoginUrl)
driver.find_element_by_name('strLogin').send_keys(Email)
el = driver.find_element_by_name('strPwd')
el.send_keys(Pass)
el.submit()

driver.find_element_by_class_name('caret').click()
driver.find_element_by_xpath(f"//span[text()='BMW']").click()
1 голос
/ 13 апреля 2019

О том, как выбрать дату в средстве выбора даты начальной загрузки:

WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, "datemec")))
el = driver.find_element_by_xpath("//*[@id='datemec']/parent::div/span")
el.click()

n = 0
while True:
    driver.find_element_by_xpath("//div[contains(@class, 'datepicker-years')]//th[contains(@class,'prev')]").click()
    el = driver.find_element_by_xpath("//span[@class='input-group-addon']")
    try:
        el.find_element_by_xpath(f"//span[text()='2000']").click()
        break
    except Exception as e:
        if n > 3:
            raise
        n += 1
...