【问题标题】:Selenium python hidden element cant be clicked unless hovered over除非将鼠标悬停在上面,否则无法单击 Selenium python 隐藏元素
【发布时间】:2022-11-19 22:39:25
【问题描述】:

我想创建一个程序,当我运行它时会自动托管一个 krunker 地图,但要托管它,该程序必须单击一个按钮,该按钮仅在您将鼠标悬停在地图上时才会显示,我不知道如何使用 selenium 执行此操作(ps我要将服务器设置为私有,我不认为我可以通过链接来做到这一点,我不想使用任何像 pyautogui 那样移动鼠标的代码。如果有更好的方式来托管私人自定义地图(带密码),请分享。

driver = uc.Chrome()
    driver.get('https://krunker.io')
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[@id='onetrust-accept-btn-handler']"))).click()
    WebDriverWait(driver, 30).until(EC.element_to_be_clickable((By.XPATH, "//div[@id='menuBtnHost' and contains(., 'Host Game')]"))).click()
    WebDriverWait(driver, 30).until(EC.element_to_be_clickable((By.XPATH, "//div[@id='menuWindow' and contains(., 'Custom')]"))).click()
    WebDriverWait(driver, 30).until(EC.element_to_be_clickable((By.XPATH, "//div[@id='hostCMapPickr']"))).click()
    WebDriverWait(driver, 30).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='bigMenTab' and contains(., 'search')]"))).click()
    WebDriverWait(driver, 30).until(EC.element_to_be_clickable((By.XPATH, "//div[@id='mapList']"))).click()
    mapname = driver.find_element(By.ID,"mpSrch")
    mapname.send_keys('Zombie_Bulwark')
    mapname.send_keys(Keys.ENTER);
                                                          <<<what must i do here to click the button?
    WebDriverWait(driver, 30).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='mapActionB']"))).click()                                       <<<button i wanna click

【问题讨论】:

  • 地图的 xpath 是什么?
  • <div class="mapActionB" title="Host" onclick="selectHostMap("Zombie_Bulwark","undefined","114845","Keybi",1)"><span class="material-icons" style="font-size:70px;color:#fff;">video_settings</span></div> 这是我试图点击的按钮
  • 您需要将鼠标悬停在地图上才能单击按钮吗?
  • 是的,但我想以一种你可以无头的方式来做

标签: python selenium-webdriver


【解决方案1】:

有一种方法可以在硒中模拟鼠标悬停

您可以尝试以下操作

from selenium import webdriver
from selenium.webdriver import ChromeOptions
from selenium.webdriver.common.action_chains import ActionChains

options = ChromeOptions()
options.add_argument("--start-maximized")
driver = webdriver.Chrome(options=options)

mapp = driver.find_element(By.XPATH, 'put the map xpath here')
mousehover = ActionChains(chrome_driver)
mousehover.move_to_element(mapp)
mousehover.perform()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-02
    • 1970-01-01
    • 2011-11-08
    • 2013-05-01
    • 2021-07-15
    • 1970-01-01
    相关资源
    最近更新 更多