使用ActionChains的Selenium Python

2024-05-02 23:48:30 发布

您现在位置:Python中文网/ 问答频道 /正文

enter image description here我的代码打开一个网站并使用actionChains,它右键单击桌面上的菜单。我现在需要用actionChains做3件事。我需要将鼠标悬停在显示savepage WE的项目上,然后单击弹出的子菜单上的一个项目,然后单击enter按钮。谁能告诉我怎么做吗?谢谢

from selenium import webdriver

    from selenium.webdriver import ActionChains
    fp = webdriver.FirefoxProfile('/Users/Jake/AppData/Roaming/Mozilla/Firefox/Profiles/emjx467y.default-1524932841911')
    driver = webdriv[enter link description here][1]er.Firefox(fp)
    driver.get('http://www.tradingview.com/screener')
    element = driver.find_element_by_link_text('Screener')
    actionChains = ActionChains(driver)
    actionChains.context_click(element).perform()

Tags: 项目代码fromimportdriverselenium菜单link
1条回答
网友
1楼 · 发布于 2024-05-02 23:48:30

通过使用这一行:actionChains.context_click(element).perform(),您正试图右键单击Screener菜单。但理想的行为应该是在上面悬停并从3个选项中选择一个。在

我正在选择外汇筛选工具,您可以根据您的要求选择任何一个。在

对于hover over,可以尝试以下代码:

actionChains.move_to_element(element).perform()  

完整代码如下:

^{pr2}$

请确保导入这些:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC 
from selenium.webdriver.common.action_chains import ActionChains

相关问题 更多 >