【发布时间】:2021-11-24 12:03:11
【问题描述】:
这是下拉菜单:
和
默认情况下它位于Range,我希望我的脚本将其移至Custom
我尝试了几种方法,但都停留在滚动菜单上(第二张图片)并且没有选择Custom
到目前为止,这是我的代码:
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)
我收到了这个错误:
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
编辑2:
我冻结了浏览器的检查器以可视化下拉列表的html并且没有Select
【问题讨论】:
-
可能是,但也许我做错了?我收到了这个错误:
selenium.common.exceptions.UnexpectedTagNameException: Message: Select only works on <select> elements, not on <div> -
我编辑了我的帖子
-
讨厌,在控制台/F12模式下选择下拉菜单。在控制台类型: $0.Click() 下拉应该出现。现在尝试导航到元素下的任何内容以获取真正的 html。也许页面按钮处的一些隐藏元素出现了?
-
F12 模式?你的意思是检查?
标签: python-3.x selenium