【发布时间】:2023-04-09 04:39:02
【问题描述】:
我想选择一个仅在您单击下拉菜单后才显示的选项(参见附图)。我已经能够单击下拉列表以获取列表,但无法弄清楚如何在列表出现后单击选项,例如选项 1,“最后一天”。
这是我目前所拥有的:
from selenium import webdriver
binary = FirefoxBinary('C:\\Program Files\\Firefox Developer Edition\\firefox.exe')
cap = DesiredCapabilities().FIREFOX
cap["marionette"] = True
url='https://www.glassdoor.com/Job/jobs.htm?suggestCount=0&suggestChosen=false&clickSource=searchBtn&typedKeyword=data+sc&sc.keyword=data+scientist&locT=C&locId=1154532&jobType='
driver = webdriver.Firefox(firefox_binary=binary, capabilities=cap, executable_path=GeckoDriverManager().install())
driver.get(url=url)
driver.implicitly_wait(10)
driver.maximize_window()
# clicking on dropdown
d = driver.find_element_by_id('filter_fromAge')
d.click()
我也尝试使用以下代码(在另一个 SO 答案中找到)但它也不起作用:
element = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR,"ul#css-1dv4b0s ew8xong0")))
我是网络抓取的新手,不太熟悉 XPATH 以及如何处理操作。感谢您的帮助!
【问题讨论】:
-
在回答部分查看您的问题的解决方案,对于您的 xpath,下面可能是很好的开始品脱 lambdatest.com/blog/… selenium-python.readthedocs.io/locating-elements.html guru99.com/xpath-selenium.html
-
尝试使用 点击。
标签: python-3.x selenium selenium-webdriver xpath webdriverwait