1

Here's the dropdown menu :

dropdown

and

dropdown2

It's on Range by default and I would like my script to move it to Custom

I tried several ways, but all stay on the scrolldown menu (the 2nd picture) and didn't pick Custom

Here's my code so far :

from selenium import webdriver

from selenium.webdriver.support.select import Select
from selenium.webdriver.support.ui import WebDriverWait     
from selenium.webdriver.common.by import By     
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys

url = 'https://www.mergermarket.com/homepage'
driver.get(url)
deals = driver.find_element_by_xpath('//*[@id="header"]/div/div[2]/nav/ul/li[4]/a')
urldeals = deals.get_attribute("href")
driver.get(urldeals)

body_element = driver.find_element_by_xpath('//*[@id="searchCriteriaSummary"]/div[4]/div/div[2]/div/div[1]/div[2]/div/div/div[1]/div[1]')

custom = driver.find_element_by_xpath('//*[@id="searchCriteriaSummary"]/div[4]/div/div[2]/div/div[1]/div[2]/div/div/div[1]/div[1]')
custom.click()
custom.send_keys('Custom') 
custom.click()
time.sleep(1)

I got this error :

selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable

EDIT2 : I froze the brower's inspector to visualise the html of the dropdown and there is not Select

dropdown

LaurieFalcon
  • 103
  • 1
  • 7
  • 1
    Does this answer your question? [How to select a drop-down menu value with Selenium using Python?](https://stackoverflow.com/questions/7867537/how-to-select-a-drop-down-menu-value-with-selenium-using-python) – Nandan A Nov 24 '21 at 12:08
  • It could be but maybe I did it wrong ? I got this error : `selenium.common.exceptions.UnexpectedTagNameException: Message: Select only works on – LaurieFalcon Nov 24 '21 at 14:17
  • I edited my post – LaurieFalcon Nov 24 '21 at 14:25
  • Nasty, select the dropdown in the console/F12 mode. In the console type: $0.Click() the dropdown should appear. Now try to navigate to whatever it is under elements to get the real html. Maybe some hidden elements at the button of the page appear? – Taco Verhagen Nov 24 '21 at 21:05
  • F12 mode ? You mean inspect ? – LaurieFalcon Nov 25 '21 at 08:27

1 Answers1

0

Complete rewrite, it turns out this is NOT a normal Select where we can use the Selenium Select class. Different approach, try to get the element which IS clickable. Your xPath is very long and I can't see which element is targets. Could you try these options? Currently you send a sendKeys to a div, which Selenium finds odd as it is not a textfield (it should be a Select, but we need to live with that)

custom.click()
driver.find_element_by_xpath('//div[@id=""react-select-12-option-0"]').click()
# or this one
custom.find_element_by_xpath('//div[contains(text(), "Custom")]')
Taco Verhagen
  • 222
  • 1
  • 6