1

I am trying to select an option from http://www.lacoteargus.ma/cote-maroc/recherche/
But I am getting this error:
selenium.common.exceptions.ElementNotVisibleException: Message: element not interactable: Element is not currently visible and may not be manipulated
in this line
Brands.select_by_visible_text('BMW')


Here is my script:

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')

I have also tried:
Brands.select_by_value('1')
and
Brands.select_by_index('1')

None of them are working.

3
  • What is the correct way to select an <option> using Selenium's Python WebDriver Commented Apr 13, 2019 at 10:39
  • 1
    Its a select2 or similar element, not a simple select element. If you query //[text()='BMW'] you will see two elements (the first is the hidden option and the second is the span that you want to click to trigger the select). Commented Apr 13, 2019 at 11:04
  • 1
    I suggest that you don't use the time.sleep, its not recommended and you will spend to much time were you don't want to. See WebDriverWait() function. Commented Apr 13, 2019 at 11:06

2 Answers 2

2

Its not a select element, the select element is hidden.

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()
Sign up to request clarification or add additional context in comments.

3 Comments

Awesome @filipe you are genius. Thanks a lot.
Have you seen the date field below? can I select 2010 January? @filipe
Added another response for that question.
1

About how to select a date on the bootstrap date picker:

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

1 Comment

Thanks, Man! It's working like a charm. Thank you so much. @filipe

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.