开发者社区> 问答> 正文

不能点击下拉按钮硒Python

我想点击元素“Project”来显示下拉列表(见下图) 在python的其他地方使用selenium库,我得到错误:

could not be scrolled into view

例如,使用以下代码获得:

driver = webdriver.Firefox()
driver.get(url)
driver.find_element_by_xpath('//div[@class="multiselect-container"]').click()

或者使用一些代码,我等待元素被显示,例如如下所述: 消息:元素

无法在通过Selenium单击下拉菜单中的某个选项时滚动到视图中
mySelectElement = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, "edit-projects")))
mySelectElement.click()

但是我不能让它工作。 任何一个都可以。 html的源代码可以在这里找到: https://rpidejr.hopto.org/f/8a909b51dcc34d09a00a/

问题来源StackOverflow 地址:/questions/59382985/cant-click-on-dropdown-button-selenium-python

展开
收起
kun坤 2019-12-27 16:56:08 424 0
1 条回答
写回答
取消 提交回答
  • 我将源代码文件以test.html的形式保存到驱动器中,然后打开它,用下面的代码单击Project框。只需编辑到本地机器的路径。

    from selenium import webdriver
    import time
    
    driver = webdriver.Firefox(executable_path=r'C:\\Path\\To\\geckodriver.exe')
    
    driver.get("file:///C:/Path/To/test.html")
    
    time.sleep(1)
    #project = driver.find_element_by_xpath("//select[@id='edit-projects']")
    #project.click()
    
    project_elements = driver.find_elements_by_xpath("//select[@id='edit-projects']")
    for element in project_elements:
        try:
            element.click()
        except Exception as e:
            print(e)
    
    2019-12-27 16:56:15
    赞同 展开评论 打赏
问答分类:
问答标签:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
From Python Scikit-Learn to Sc 立即下载
Data Pre-Processing in Python: 立即下载
双剑合璧-Python和大数据计算平台的结合 立即下载