Python 如何在鼠标悬停在不可见的元素上之前单击该元素?

Python 如何在鼠标悬停在不可见的元素上之前单击该元素?,python,selenium,Python,Selenium,我使用python3.6和selenium3.6在Safari 11下的www.tradingview.com上测试图表。当我想在鼠标悬停在图表上之前通过单击不可见元素缩小图表时 driver.get('https://www.tradingview.com/chart/f8my3Ybg/') zoom_out_button = driver.find_elements_by_class_name('zoom-out-right-button-control-bar') Time.sleep(5

我使用python3.6和selenium3.6在Safari 11下的www.tradingview.com上测试图表。当我想在鼠标悬停在图表上之前通过单击不可见元素缩小图表时

driver.get('https://www.tradingview.com/chart/f8my3Ybg/')
zoom_out_button = driver.find_elements_by_class_name('zoom-out-right-button-control-bar')
Time.sleep(500)
ActionChains(driver).move_to_element(zoom_out_button).click().perform()
它会显示一条错误消息

an element command could not be completed because the element is not visible on the page
我在网上搜索,却找不到纠正的方法。下面是我分析的代码。我如何在一个看不见的元素上实现这样的操作? 我分析的HTML代码 而不是:

ActionChains(driver).move_to_element(zoom_out_button).click().perform()
首先尝试按如下方式悬停:

ActionChains(driver).move_to_element(zoom_out_button).click("xpath_css_hidden_element").perform()
而不是:

ActionChains(driver).move_to_element(zoom_out_button).click().perform()
首先尝试按如下方式悬停:

ActionChains(driver).move_to_element(zoom_out_button).click("xpath_css_hidden_element").perform()

我看到很多弹出窗口以未注册用户的身份出现在这个页面上。这些阻碍了我尝试我们的代码。您是否以注册用户的身份与此页面进行交互,以便不获取这些弹出窗口?作为注册用户,弹出窗口也会出现,但并不频繁。我在处理弹出窗口时仍然有一些问题,因为我阻止截屏。我看到很多弹出窗口以未注册用户的身份出现在这个页面上。这些阻碍了我尝试我们的代码。您是否以注册用户的身份与此页面进行交互,以便不获取这些弹出窗口?作为注册用户,弹出窗口也会出现,但并不频繁。我在处理弹出窗口时仍然遇到一些问题,因为我无法截屏。感谢您的帮助,我尝试了ActionChains(驱动程序)。将\u移动到\u元素(缩小按钮)。构建().perform(),然后收到一条错误消息,显示“ActionChains(驱动程序)。将\u移动到\u元素(缩小按钮)。构建().perform()AttributeError:“ActionChains”对象没有属性“build”ActionChains(驱动程序)。移动到元素(缩小按钮)。执行()打印(“计时器50秒!”)时间。睡眠(50)ActionChains(驱动程序)。单击(缩小按钮)更新我的答案。让我知道状态。ActionChains(驱动程序)。移动到元素(缩小按钮)。\单击(“/html/body/div[1]/div[1]/div/div[2]/div[2]/div/svg[2]”。perform()我对您的语句单击(“xpath\u css\u hidden\u元素”)感到困惑,我只是将其替换为从Safari获得的xpath。失败时显示一条消息”AttributeError:'str'对象没有属性'id',我曾尝试通过xpath获取元素,如缩放按钮xpath=driver。通过xpath(“html/body/div[1]/div[1]/div[2]/div[2]/div/svg[2]”查找元素,但也失败。很抱歉,我是新手。要处理
svg
元素,请遵循此操作。谢谢您的帮助,我尝试了ActionChains(驱动程序)。将\u移动到\u元素(缩小按钮)。build().perform(),然后收到一条错误消息,显示为“ActionChains(驱动程序)。将\u移动到\u元素(缩小按钮)。build().perform()AttributeError:“ActionChains”对象没有属性“build”ActionChains(驱动程序)。移动到元素(缩小按钮)。执行()打印(“计时器50秒!”)时间。睡眠(50)ActionChains(驱动程序)。单击(缩小按钮)更新我的答案。让我知道状态。ActionChains(驱动程序)。移动到元素(缩小按钮)。\单击(“/html/body/div[1]/div[1]/div/div[2]/div[2]/div/svg[2]”。perform()我对您的语句单击(“xpath\u css\u hidden\u元素”)感到困惑,我只是将其替换为从Safari获得的xpath。失败时显示一条消息”AttributeError:'str'对象没有属性'id',我曾尝试通过xpath获取元素,如缩放按钮xpath=driver。通过xpath(“html/body/div[1]/div[1]/div[2]/div[2]/div/svg[2]”查找元素,但也失败。很抱歉,我是新手。要处理
svg
元素,请遵循以下步骤