這是下拉選單:

和

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
EDIT2 :我凍結了瀏覽器的檢查員以可視化下拉串列的 html 并且沒有 Select

uj5u.com熱心網友回復:
完全重寫,事實證明這不是我們可以使用 Selenium Select 類的普通 Select。不同的方法,嘗試獲取可點擊的元素。您的 xPath 很長,我看不到哪個元素是目標。你能試試這些選項嗎?目前您將 sendKeys 發送到一個 div,Selenium 發現它很奇怪,因為它不是一個文本欄位(它應該是一個 Select,但我們需要忍受它)
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")]')
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/367181.html
上一篇:嗨,有人可以解釋這個錯誤是什么意思,我能做些什么來阻止這個按鈕?
下一篇:根據另一個單元格值設定約束
