【问题标题】:Selenium : Unable to mouseover an elementSelenium:无法将鼠标悬停在元素上
【发布时间】:2017-03-07 05:37:27
【问题描述】:

我正在尝试访问页面 DOM 中的元素。我能够获取元素并打印它,但无法单击它。主要原因是当您将鼠标悬停在其上时会出现一个页面切换,并且当您将鼠标指针移开时会检索该切换。切换顶部有一个按钮,由于此切换功能,我无法单击该按钮。我尝试了鼠标悬停、显式等待和所有其他操作,但无法单击按钮。当我尝试打印页面源时,我可以看到所有元素,但由于某种原因它对 selenium 不可见。

要点击的按钮:

属性名称:data-aid="sb-toggle"

self.driver.find_element_by_css_selector('[data-aid="sb-toggle"]').click()

也试过这个:

page-sidebar 是标签,它是页面中可见的切换。

sideBar = self.driver.find_element_by_class_name('page-sidebar') toggleButton = self.driver.find_element_by_css_selector('[data-aid="sb-toggle"]') hover = ActionChains(self.driver).move_to_element(sideBar).move_to_element(toggleButton) hover.click().build().perform()

MoveTargetOutOfBoundsException:消息:元素内的偏移量无法滚动到视图中:(140, 288): [object HTMLDivElement]

我没有收到未找到元素的异常,因为在页面源中找到了该元素。

【问题讨论】:

    标签: python selenium


    【解决方案1】:
    hover = ActionChains(self.driver).move_by_offset(1,1)
        hover.click(self.driver.find_element_by_css_selector('[data-aid="sb-toggle"]')).perform()
    

    如果我将鼠标悬停在页面的左上角然后单击按钮,则偏移量(1,1)。

    【讨论】:

      猜你喜欢
      • 2011-11-08
      • 2021-07-15
      • 2020-01-03
      • 1970-01-01
      • 1970-01-01
      • 2021-11-02
      • 1970-01-01
      • 2011-06-02
      • 2017-09-18
      相关资源
      最近更新 更多