Home > database >  How to click on webpage based on coordinates?
How to click on webpage based on coordinates?

Time:04-11

I need your help on clicking on a webpage. When connecting on a website, the login page opens automatically as a popup in the middle of the page. The unique way to close the pop-up is by clicking in any place around the pop-up itself. With python I've already tried with clickin on the html but after that the website recognize that I'm using a bot to navigate the website. So there is a way to fake the mouse clicking on coordinates like X= 1300 Y=700 (a spot around the pop-up) using selenium or any other way?

Many thanks

CodePudding user response:

You can use move_by_offset method which is present in ActionChains class.

The internal code description is shown below:

def move_by_offset(self, xoffset, yoffset):
    """
    Moving the mouse to an offset from current mouse position.

    :Args:
     - xoffset: X offset to move to, as a positive or negative integer.
     - yoffset: Y offset to move to, as a positive or negative integer.
    """

So, your effective code would be:

from selenium.webdriver.common.action_chains import ActionChains
ActionChains(driver).move_by_offset(1300, 700).pause(2).click().perform()
  • Related