Home > OS >  Mouse-click without moving cursor in headless mode
Mouse-click without moving cursor in headless mode

Time:09-01

Is it possible to click on coordinates in headless mode? Something like this command:

pg.click(3891, 271)

CodePudding user response:

just found the solution to this myself, try

driver.execute_script("arguments[0].click();", element)

I needed this to click an element that was behind a banner ad. so this clicks the element directly through Javascript

CodePudding user response:

If you want to click using X,Y coordinate you can do like below:

action = ActionChains(driver)
action.move_by_offset(x_coordinate, y_coordinate)
action.click()
action.perform()

import

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

Make sure to maximize the window driver.maximize_window() before click

  • Related