在網站上有一個下拉選單"Best Time to Contact",我點擊它,但我無法從 dd 選單中進行選擇。建議?
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
driver=webdriver.Chrome(executable_path="D:\ChromeDriverExtracted\chromedriver")
driver.get("https://fs2.formsite.com/meherpavan/form2/index.html?1537702596407")
select = Select(driver.find_element_by_id("RESULT_RadioButton-9").click())
select.select_by_visible_text("Morning").click()
uj5u.com熱心網友回復:
我運行了下面的代碼
driver.maximize_window()
wait = WebDriverWait(driver, 30)
select = Select(wait.until(EC.visibility_of_element_located((By.ID, "RESULT_RadioButton-9"))))
select.select_by_visible_text('Evening')
進口:
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
它做到了。這是帶有顯式等待的,這在 Selenium 自動化中是推薦的。
你不應該.click()在這里使用
select = Select(driver.find_element_by_id("RESULT_RadioButton-9").click())
另外,我在沒有 的情況下測驗了您的代碼.click(),它也能正常作業。
select = Select(driver.find_element_by_id("RESULT_RadioButton-9"))
select.select_by_visible_text("Morning")
uj5u.com熱心網友回復:
這對我有用
driver.find_element(By.CSS_SELECTOR, "#RESULT_RadioButton-9 > option:nth-child(2)").click()
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/363767.html
上一篇:為什么在seleniumpython腳本中獲取selenium.common.exceptions.NoSuchElementException?
