Home > database >  Selenium python hidden element cant be clicked unless hovered over
Selenium python hidden element cant be clicked unless hovered over

Time:11-22

I want to create a program that will automatically host a krunker map when i run it but to host it the program has to click a button which only shows up if u hover over the map and i dont know how to do that with selenium (ps im gonna set the server to private and i dont think i can just do that with a link and i dont wanna use any code that moves the mouse like pyautogui. If there is a better way to host a pivate custom map (with password) please share.

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

CodePudding user response:

Update

There is a way to simulate the mousehover in selenium

You can try the following

import undetected_chromedriver as uc # pip install undetected-chromedriver
from selenium.webdriver.common.action_chains import ActionChains

driver = uc.Chrome()

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

# your mouse click
# WebDriverWait(driver, 30).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='mapActionB']"))).click() 
  • Related