gpt4 book ai didi

python - python selenium中的鼠标悬停操作

转载 作者:太空宇宙 更新时间:2023-11-03 15:48:55 26 4
gpt4 key购买 nike

我尝试在 python selenium 绑定(bind)中执行鼠标悬停操作,但在使用 ActionChains.perform() 时出现错误

我已经尝试过了

def test_mouse_over():

driver =webdriver.Firefox()
driver.get("https://www.flipkart.com/")

actions = ActionChains(driver)
val1 = driver.find_element_by_xpath('//span[text()="Men"]')
actions.move_to_element(val1)
val2 = driver.find_element_by_xpath('//span[text()="Shirts"]')
actions.click(val2)
actions.perform()

我在最后一行遇到错误 actions.perform()

最佳答案

您不需要连续执行这两个操作。尝试以下代码:

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

driver = webdriver.Firefox()
driver.get("https://www.flipkart.com/")

actions =chains(driver)
val1 = driver.find_element_by_xpath('//li[a[@title="Men"]]')
actions.move_to_element(val1).perform()
val2 = wait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, '//a[span[text()="Shirts"]]')))
val2.click()

关于python - python selenium中的鼠标悬停操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41502619/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com